Scriptaculous: How to make blind or slide smooth and not jump? Or is it not possible? - scriptaculous

I was seeing a strange phenomena when using Scriptaculous BlindDown and SlideDown effects, where they would smoothly slide, and then at the very end, they would jump an additional amount, maybe 10% of the slide distance.
I already saw the note on the BlindDown page that you have to be sure not to use padding, which I'd already done.
I was still thinking that this must be my mistake somehow, when I noticed that I see the exact same thing happening on their demo page for Toggle when clicking on either the Blind or Slide demos:
http://wiki.github.com/madrobby/scriptaculous/effect-toggle
Firefox 3.6.7, Chrome 6, and Internet Explorer 8 all display this effect on my computer.
So I was thinking about just writing it off and either living with it or cutting the effect out, when I noticed that the page for BlindDown does not display this effect:
http://wiki.github.com/madrobby/scriptaculous/effect-blinddown
So there must be a way to make this work. On my page, the jump is occurring whether I directly use BlindDown/Slide or whether I use Toggle.
Has anyone out there used these and managed to do so without this problem? Any ideas on what the secret is?

It's usually due to margin or padding.
The element you're blind-downing mustn't have any margin or padding, or should have margin:0.1% so that contained margins don't collapse through the bounds of the element either. If you do this it'll be smooth as silk.
also - ensure you've set overflow:hidden
Enjoy.
(the other place it'll fall down is if you don't define height. If you do this little incantation before you animate it'll get and set you height without bothering anything else.
elem.setStyle({position:'absolute',visiblity:'invisible'});
elem.setStyle({'height':elem.getDimensions().height+'px'});
elem.setStyle({position:'relative',visibility:'visible'}); //or position:'static'

In my experience, the jumping is just a performance issue, which is effected by the system specs, browser, and complexity of the html content you are toggling. Some browsers like safari and chrome have a pretty good javascript engine making them more efficient.
I see this is happening for you even when using chrome though? Is the html content particularly complex, or your computer overloaded with applications running?

There is definitely a little very well known secret... Have you tried wrapping your content in an extra div container? You should consider this best practice and almost a requirement specifically when using Scriptaculous effects.
For example... Say you want to slideDown or Toggle a login form - and you have::
<div id="login-panel">
<input type="text" name="username" />
<button type="submit" name="send">Login</button>
</div>
All you have to do is add an extra inner div tag::
<div id="login-panel">
<div><!-- extra div here -->
<input type="text" name="username" />
<button type="submit" name="send">Login</button>
</div><!-- close it here -->
</div>
Now when you do something like Effect.toggle("login-panel", 'slide'); the transition should be much smoother and less jumpy. It may seem a little sloppy but it almost always helps. Hope this helps you!!

Keep in mind that when Scriptaculous begins an animation, the container that is being modified will be absolutely positioned and then a record of the height will be taken, similar to what danielsherson mentions. If however the container does not exist within a relatively positioned parent container, then the dimensions of the animating container may change quite drastically. The easiest way to test this is to modify your container using firebug to set the position to absolute. What happens? Did the height change? For the best results, there should be no change in the dimensions of your animating container when switching to absolute positioning. What happens to the rest of your document, such as content moving underneath, will not matter.
The padding/margin issue is a tricky one too since there really isn't a way to prevent the margins from overlapping and creating issues. Best way I found to address this is to set your animating container to float and then use the clearfix hack on a parent container to make sure nothing overlaps.
<body style="margin: 0 auto; width: 300px; position: relative; background: black;">
<div class="parent nonanimating clearfix">
<div class="animating" style="float: left; width: 100%; background: white;">
<div class="apply-your-margins-and-padding-here">
...content...
</div>
</div>
</div>
<div class="parent nonanimating clearfix">
<div class="animating" style="float: left; width: 100%; background: white;">
<div class="apply-your-margins-and-padding-here">
...content...
</div>
</div>
</div>
</body>
Note that the classes are not functional and just for reference to my comments with the exception of clearfix, which is the float clear hack. The backgrounds and widths are only specified to give a better example of what is happening. Add whatever animation you'd like to $$('.animating')
I use this one (there are many), all though it is old and I don't even design for many of the browsers this hack supports..
.clearfix:after {
content: ".";
display: block;
clear: both;
visibility: hidden;
height: 0;
}
.clearfix {
display: inline-block;
}
/* Hides from IE-mac \*/
* html .clearfix {height: 1%;}
.clearfix {display: block;}
/* End hide from IE-mac */

I don't think it's a performance issue at all. I'm having the same issue. The ONLY way I've been able to make it not jump is to define a height for the div I'm sliding. I realize that this is NOT a good solution but it's the only one I've been able to find. I've also tried adding the additional div and it had no effect on how the Effect.toggle slide worked.
If anyone else has any more info on this, I'm all ears.

To prevent a Scriptaculous effect from jumping or jerking, remove the 'style' attribute from the element which you are applying the Effect to.
This:
<div id="mydiv" style="padding:10px;margin:10px;">
<button onClick="new Effect.BlindUp('mydiv');" />
</div>
Becomes:
<div id="mydiv">
<button onClick="new Effect.BlindUp('mydiv');" />
</div>
The styling can be placed in a enclosed div like this:
<div id="mydiv">
<div style="padding:10px;margin:10px;">
<button onClick="new Effect.BlindUp('mydiv');" />
</div>
</div>
The problem is caused by Scriptaculous reapplying the element's (mydiv) inline style declarations after the effect has been performed.

I have found success with using position: relative; on the block element using the slide/blind animation. Make sure padding/margins are placed on the child elements and not the slide block element.

Related

Modal Dialog is obscured by opaque background

I am using Element's Notification component but when it is activated the dialog appears but seems to be "behind" the grey background that is also introduced. Clicking anywhere removes the grey background and allows the interaction with the dialog box but without the greyed out background that should be filtering out the noise of the normal screen. Here is a short video that shows the various states:
video
The code to put the component in as follows:
<div class="add-address" #click="showAddDialog = true">
+
</div>
</div>
<el-dialog
title="Add New Address"
:visible.sync="showAddDialog"
width="30%"
:before-close="newAddressDialogClosed">
<span>Postal Address</span>
<el-input v-model="newAddress" type="text"></el-input>
<span slot="footer" class="dialog-footer">
<el-button #click="dialogVisible = false">Cancel</el-button>
<el-button type="primary" #click="dialogVisible = false">Confirm</el-button>
</span>
</el-dialog>
I have used the inspector to poke around at the CSS but I haven't yet understood what's causing this from a CSS perspective nor a Vue/Element perspective. Any help would be appreciated.
I have further analyzed the HTML/CSS and the component appears to introduce two separate blocks in the DOM:
The lower block is the grey background which you'd expect to "blur" the page and focus attention on the modal. It, however, is in front of the dialog. Also of interest is that clicking anywhere seems to target the grey background and dismiss it but in so doing it also has a subtle effect on the placement on the dialog box as can be seen here:
Note that the z-index of the dialog box is greater than the background which intuitively makes sense to me but I'd have thought this would have put the dialog box on top. Guess that's not all there is to this.
I have hacked a work-around for now by changing the background to display: none and then adding the following HTML directly before the modal dialog in the DOM:
<div class="modal-background" v-if="showAddDialog"></div>
These seems to validate my underlying suspicion that placement within the DOM tree is important and the component's attempt to place the modal background at the very end of the DOM is somehow problematic.
I had the same issue and also found changing the z-index of the dialog had no effect. This was occurring when I had nested Element.Eleme.io elements, which appears to be the case for you also.
The z-index is not quite as simple as "higher always means on top". Elements are grouped into different stacking contexts; it is not possible for an element in a lower stacking context to appear above an element in a higher stacking context. Therefore depending on where the different elements were rendered in the DOM, they can land themselves in different stacking contexts, and are destined to remain at the same relation to one another, no matter how much the z-index has changed. (See https://philipwalton.com/articles/what-no-one-told-you-about-z-index/ for a more detailed explanation on the z-index).
Examining with Chrome dev tools, I found that the obscuring modal is not rendered in the same place as the dialog; in fact it is appended to the body, i.e. on the outer reaches of the application, which appears to be the reason they are not within the same stacking context. There is a quick fix; the dialog element has a property "modalAppendToBody". If true, the modal is rendered to the body, and if false it is rendered to the parent element of the dialog. By specifying this as false I managed to solve the issue:
<el-dialog
title="Add New Address"
:visible.sync="showAddDialog"
width="30%"
:before-close="newAddressDialogClosed
:modalAppendToBody="false">
</el-dialog>
you can use the CSS property called z-index
either any object which you want to set to back ? you just have to set z-index: -1; // or more
or you want to set any object on to the front of another ? you just have to set z-index: 1; //or more
Check the Snipet For More Info :
.a {
position: absolute;
left: 0px;
top: 0px;
z-index: -1;
}
.b {
margin-top:150px;
position: absolute;
left: 0px;
top: 0px;
z-index: 1;
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1> I am on Image</h1>
<img class="a" src="http://qnimate.com/wp-content/uploads/2014/03/images2.jpg" width="100" height="140">
<br>
<br>
<br>
<br>
<h1> Image is on me</h1>
<img class="b" src="http://qnimate.com/wp-content/uploads/2014/03/images2.jpg" width="100" height="140">
</body>
</html>

Angular Material - mdContent doesn't scroll properly

I'm using angular material to create a page with a fixed toolbar on the top and a md-content next to the toolbar. However I can't make the toolbar sticky. I've read the documentation for many times, it should be simply like:
<body layout="column">
<md-toolbar>
...
</md-toolbar>
<md-content>
...
</md-content>
</body>
and md-content should be set as overflow: auto already. But just like the first example in the documentation, even I set overflow to scroll. It still doesn't work.
Please see the codepen
Set your height on the element that needs to be scrolled or else it won't know what portion needs to scroll.
<md-content flex="" layout-padding="" style="overflow: auto; height: 200px;">

jquerymobile image stick to bottom

I want to have an image that stick to the bottom center of the screen. I know I can use <div data-role="footer"> to do it. However the footer has a visible horizontal line on top which I want to get rid off. Any idea how to do it?
The easiest way to do this is to use the built-in jQM footer, which has the data-position="fixed" attribute to make it stick to the bottom. I'm unfamiliar with this horizontal line you say the footer has, but it'll be easy to get rid of just by overriding the default jQM stylesheet. You can view/test-edit the CSS styles using Firebug in Firefox, or the built-in developer tools in any browser.
It should look something like this:
.ui-footer {
/* Use !important to ensure the target style will be overridden! */
border: none !important;
}
And the HTML:
... <!-- rest of page -->
<div data-role="footer" data-id="fixedFooter" data-position="fixed" data-tap-toggle="false">
<img src="path/to/image.png" />
</div>

-webkit-overflow-scrolling Problems With Objects Inserted Into DOM

I'm using -webkit-overflow-scrolling:touch for native scrolling capabilities on my iPad. But I've come into quite an odd problem:
I have one div with various children. If these children are big enough to create the need for scrolling, the device properly scrolls correctly, with momentum and all. However, if this div is not big enough to require scrolling, and suddenly has elements inserted into it and now does require scrolling, you will not be able to scroll the element at all.
I hope that wasn't too incredibly confusing, but if someone could shed some light on what to do in this situation, that would be fantastic. There isn't much documentation about this property out there.
EDIT: Tried testing this a lot, and it seems now it's just a generally intermittent problem. Every 1 out of 5 times or so, scrolling just fails for my entire web app, no matter the contents.
I had the same issue and it seems like assigning the CSS class after the new DOM element is added seems to work fine:
// your code to add a div to the DOM
// the div contains a scrollable div with the content class
setTimeout(function(){
// this is using JQuery
div.find(".content").addClass("overflowScroll");
}, 1);
// CSS class
.overflowScroll {
overflow: hidden;
overflow-y: scroll;
-webkit-overflow-scrolling: touch;
}
// The HTML for the div
// I am adding a dynamic list to the content div
// which should use the overflow scroll
<div class="panel">
<div class="header">
</div>
<div class="content"></div>
</div>

How to position a line below a group of tags?

I am trying to position a horizontal line under a group of tags on an app done on asp.net mvc. I believe I have to do that on the CSS but I just can't seem to find the right way to place such line.
Every time I try, the line ends up at the right of the tags and I don't feel like using a whole bunch of is the right way by far.
<div id="section">
<div style="float:left; margin:20px">
<img alt="Upload" src="/Content/Images/Upload_yellow.png"/>
<img alt="Confirm" src="/Content/Images/Confirm_white.png"/>
<img alt="Review" src="/Content/Images/Review_white.png"/>
</div>
<hr />
</div>
Can somebody orient me in the right direction here?
Ditch the <hr /> and add this change your CSS rule to <div style="float:left; margin: 20px; border-bottom: 1px solid #000;">
If you have multiple floated divs in the section div, put the border rule on that if you want it to extend all the way across and set either overflow:hidden; or overflow:auto so it doesn't collapse (which containers do when they only contain floated elements unless overflow is set). This way you can avoid setting a clear rule or adding extra markup for the line.
<hr style="clear: left" />
Jeff and Joel talked about this in Podcast #4. Specifically, the CSS-extremists would prefer you do that in CSS, but practical concerns override that. Keep it where it is now.

Resources