Results 1 to 4 of 4

Thread: Animating height turned out funny

  1. #1
    Join Date
    May 2014

    Question Animating height turned out funny

    I have just started to learn javascript and I decided that I wanted to create an animated drop-down list with it in order to learn more, however there is a problem I cant seem to resolve. Sometimes, if I try to animate the height on a part of the page that is already being animated at the time the finishing height is undesirable.
    Here is the code for animation:
    function AniHeight(ElId,duration,endHeight)
    	"use strict";
    	this.id = ElId;
    	this.steps = duration / 25;
    	this.heightDifference = endHeight - document.getElementById(this.id).offsetHeight;
    	this.addHeight = this.heightDifference / this.steps;
    	this.incrementHeight = function()
    		if(this.steps > 0)
    			document.getElementById(this.id).style.height = (document.getElementById(this.id).offsetHeight + this.addHeight) + 'px';
    			this.steps -= 1;
    	this.resetAnimation = function(desiredHeight,length)
    		this.steps = length / 25;
    		this.heightDifference = desiredHeight - document.getElementById(this.id).offsetHeight;
    		this.addHeight = this.heightDifference / this.steps;
    var heightObjects =[];
    function animateHeight(ElId,endHeight,duration)
    	var objectExists = false;
    	for(var i = 0; i < heightObjects.length ; i+= 1)
    		if (heightObjects[i].id === ElId)
    			objectExists = true;
    	if(objectExists === false)
    		heightObjects.push( new AniHeight(ElId,duration,endHeight) );
    	"use strict";
    		for(var i = 0; i < heightObjects.length; i +=1)
    Here is the html for the page I am trying to animate:

    	<title>Javascript testing page</title>
    <body align="center">
    	<h1> output</h1>
    	<p id = "output"></p>
    	<div style = "height:300px;
    				  top:0;" id = "redbox" onmouseover="animateHeight('redbox',300,1000)" onmouseout="animateHeight('redbox',100,1000)"></div>
    	<script src="javascript.js"></script>

  2. #2
    What you have here is a somewhat outdated way of doing this. My advice, let CSS do this as JS is just more code for 'nothing' and uses more battery on mobile.

    Your other code has similar dated issues, like the ALIGN attribute on body that hasn't been valid since 1997, inlining style in the markup (even in testing I advise against that), using the onevent handlers which really NEED to be deprecated since scripting should hook the markup not the other way around...

    But setting that aside, let's say you had <div id="resize"></div>

    #resize {
      -webkit-transition:height 1s;
      -moz-transition:height 1s;
      -ms-transition:height 1s;
      transition:height 1s;
    #resize:hover {
    Mind you, IE9/earlier won't get the animation -- in my book that's a serious "OH WELL!" It will still resize on hover all the way back to IE7, and if you REALLY care about IE6 you could add something like peterneds csshover3.htc as a shim. Legacy browsers don't get something silly like an animation, rounded corners, drop shadows -- who cares? Is the page still USABLE in those browsers? Yes? then why bend over backwards to make it look perfect for people who refuse to join us in THIS century.

    That said, I draw the line at "does the page WORK and deliver content" -- if you can't do that all the way back to IE 5.5 Win / 5.2 mac, you're probably doing something wrong.

  3. #3
    Join Date
    Mar 2007
    So those who have old systems in 3rd word countries can go effem selves deathshadow?

    That is a pretty poor attitude towards programming, a good programmer will provide a fall back option to support older browsers still in the field.

    If you want to animate a drop down then search the forum using the search option, this subject has been covered many time and it is a regular request so try searching for the answer!
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  4. #4
    Quote Originally Posted by \\.\ View Post
    So those who have old systems in 3rd word countries can go effem selves deathshadow?
    I'm NOT saying don't make it not work, I'm saying if they don't get some goofy pointless presentational nonsense like an animation, rounded corners, drop shadows, text-shadows and linear gradients, is it REALLY worth the effort of making the page three times larger, ten times slower and twenty times harder to maintain?

    Hence why I pointed out it will WORK without the animation (it will just pop into place full sized) all the way back to IE7, and can be made to work all the way back to IE 5.5 with a htc file like this one?

    Which BTW is what graceful degradation thanks to progressive enhancement -- one of the entire reasons for using CSS in the first place -- is all about.

    That's not telling them to go shtup themselves, that's saying "you're not getting fancy modern bits that have nothing to do with functionality because you're not on a modern browser"

    There's a difference.

    Though sadly, users in third world countries are usually more up to date than long term developed nations; you're more likely to find a Win98 or MacOS 9 user on IE 5.5 or 5.2 Mac in the US than you are anywhere else. I DO keep these users in mind in terms of FUNCTIONALITY -- THE PAGE WILL WORK -- but they don't get some artsy fartsy pointless "gee ain't it neat" animation, I'm not going to throw bloated JavaScript at a non-issue.

    ... at least, not unless it's a paying client insisting it work there, and even then at this point I'd probably tell such a client to "Golf Alpha Foxtrot Charlie" or "Golf Tango Foxtrot Oscar" unless they were REALLY willing to pay for it... usually because that level of "perfection" on legacy browsers ends up just another BOHICA situation.

    -- edit --

    Oh and a similar argument to yours could be used against the JavaScript version, since it has no graceful degradation when JS is blocked or disabled; that would be worded something like "So those who have metered connections or don't trust JavaScript in first world nations who downloaded plugins like noScript or use built-in per page script blocking in browsers like Opera can go **** themselves?"

    Which actually would hold more water, since again my approach would gracefully degrades, something the scripting only version can't do. Well, unless you attach a class to set the 100px height and positioning at the start of script execution, so the content is always shown scripting off!
    Last edited by deathshadow; 06-01-2014 at 07:08 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.09104 seconds
  • Memory Usage 2,887KB
  • Queries Executed 15 (?)
More Information
Template Usage (34):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (3)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (4)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (4)postbit
  • (4)postbit_onlinestatus
  • (4)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (73):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates