I currently have an app with UIWebView that has a scrollable div with the webkit-overflow-scrolling:touch property.
When the side menu is open, I place an overlay (another div) on top of the content to give a dimming effect.
The problem is that when the menu is open (and the overlay in place) when the user pans, the scrollable div actually scrolls when the overlay should be stopping this form happening.
Now, in iOS7, the solution was to add the webkit-overflow-scrolling:touch; to the overlay. That works like a charm, but in iOS8 it doesn't.
Here is a link to an example of the problem. If run on iOS 7 it works as expected, if run on iOS 8 the content in the back will scroll.
.scrollable {
width:100%;
height:200px;
-webkit-overflow-scrolling:touch;
overflow:scroll;
}
.overlay {
position:absolute;
width:100%;
overflow:scroll;
height:200px;
-webkit-overflow-scrolling:touch;
background-color:black;
opacity:.5;
transform: translate3d(0,0,0);
-webkit-transform: translate3d(0,0,0);
z-index:10;
}
https://jsfiddle.net/SergioM/57f2da87/9/
I also tried setting the overflow-x property of the scrollable div to hidden/auto when the menu is opened but that adds a terrible flicker.
Any suggestion will be much appreciated.
Thanks.
Well after trying many different options I came up with a work around that is good enough for now.
I added a div inside the overlay that is vertically 1% bigger. That now warranties that the event is handled by the overlay and not passed on to the container at the back.
This also allows me to listen to events natively such as pan (horizontally), the vertical ones wont come up but that is ok for now.
.overlayInner {
color:red;
height:101%;
margin-left:30px;
}
here is a link to the fiddle.The margin is unnecessary, just to avoid the number to overlap.
http://jsfiddle.net/SergioM/57f2da87/15/
i don't think this is possible by only using css in the current safari/webkit-version of iOS8.
But you should be able to prevent the scrolling with javascript.
$( ".showHide" ).click( function() {
$( ".overlay" ).toggle();
});
$( ".overlay" ).on( 'touchstart touchmove', function( event ) {
if ( $( this ).is( ":visible" ) ) {
event.preventDefault();
}
});
Update:
i played a little around and came up with another possible solution that could be helpful for you.
HTML:
<button class="showHide">show/hide overlay</button>
<br/>
<br/>
<div class="scrollable">
<div class="overlay"></div>
1
<br/>2
<br/>3
<br/>4
<br/>5
<br/>6
<br/>7
<br/>8
<br/>9
<br/>10
<br/>11
<br/>12
<br/>13
<br/>14
<br/>15
<br/>16
<br/>17
</div>
CSS:
.scrollable {
width:100%;
height:200px;
-webkit-overflow-scrolling:touch;
overflow:scroll;
position: relative
}
.overlay {
content: ' ';
position:absolute;
top: 0;
left: 0;
width:100%;
height:100%;
background-color:black;
opacity:.5;
transform: translate3d(0,0,0);
-webkit-transform: translate3d(0,0,0);
transition: opacity 300ms ease;
z-index:10;
}
Javascript:
$( ".showHide" ).click( function () {
$( ".overlay" ).toggle( { duration: 0, complete: function() {
if ( $( ".overlay" ).is( ":visible" ) ) {
$( ".overlay" ).css( 'top', $( ".scrollable" ).scrollTop() );
$( ".scrollable" ).css( 'overflow', 'hidden' );
} else {
$( ".scrollable" ).css( 'overflow', 'scroll' );
}
}});
});
Example: JSFiddle
Related
There is a gap on the right side of my page probably 10px. I could fix it using oveflow-x:hidden for the html and body but if I do this, it disable the navbar effect
<script>
$(window).scroll(function() {
var scroll = $(window).scrollTop();
if (scroll >= 120) {
$("#mainNav").addClass("scrolling");
} else {
$("#mainNav").removeClass("scrolling");
}
});
</script>
That changes the navbar background-color when scroll down.
I tried width:100% as well, but it didn't work neither.
Could someone help me to eliminate the gap without affect this function?
Thank you
Got it. See http://jsfiddle.net/uffo6you/3/ The CSS specificity ranking of .scrolling wasn't strong enough to override #mainNav. Width and overflow shouldn't have any bearing on this at all. Pls confirm?
<style>
#mainNav{
height: 20vh;
width: 80%;
background-color: blue;
color: white;
position: fixed;
}
#mainContent{
height: 200vh;
padding-top: 20vh;
}
.scrolling{
background-color: red !important;
}
</style>
<div id="mainNav">Top Navbar</div>
<div id="mainContent">
Content goes here
</div>
<script>
$(window).scroll(function() {
var scroll = $(window).scrollTop();
console.log(scroll);
if (scroll >= 80) {
$("#mainNav").addClass("scrolling");
} else {
$("#mainNav").removeClass("scrolling");
}
});
</script>
I have used the jQuery cycle2 plugin on a blog website. What i want the slideshow to do is when there is more than 1 image displayed, the controls will show-at the moment they are hidden through css.
The plugin is used by declaring it in my header (here is the link to the js file:
http://malsup.github.com/jquery.cycle2.js
And then my css contains a class for the container of the slideshow, class for the container for the buttons and a class each for prev and next buttons:
css:
.cycle-slideshow {
height:400px;
z-index:0;
}
.cycle-slideshow img{
width:100%;
height:100%;
z-index:3;
}
.center {
display:none;
}
.center a{
z-index:4;
position:absolute;
margin-top:-48px;
}
.center a:hover {
display:block;
}
.center a#prev, .center a#next{
position:relative;
width:4%;
height:60px;
width:60px;
margin-top:-60px;
font-size:40px;
text-align:center;
color:#FFF;
}
.center a#next{
float:right;
background:url(images/next.png) center -2px no-repeat;
}
.center a#prev {
float:left;
background:url(images/prev.png) center -2px no-repeat;
}
My html code is actually embedded within a wordpress function but the html format goes along the lines of:
<div class="cycle-slideshow"
data-cycle-fx="scrollHorz"
data-cycle-pause-on-hover="true"
data-cycle-speed="200"
data-cycle-next="#next"
data-cycle-prev="#prev"
data-cycle-swipe="true">
//does stuff here
</div>
<div class="center">
</div>
The following code i was told to do (the first three lines) but this still doesn't seem to work.
$(document).ready(function () {
$('.cycle-slideshow').on( 'cycle-initialized', function( e, opts ) {
if ( opts.slideCount > 1 ) {
$(".center").css("display", "block");
}
});
});
Im not the best with jQuery so can anyone help or give me any guidance please?
In this case you are going to want to initialize the slideshow via code AFTER you add the event handler. Remove the cycle-slideshow class so it doesn't auto initialize and then you can do this:
Demo: http://jsfiddle.net/lucuma/zyhrK/1/
$('.slideshow').on('cycle-initialized', function (e, opts) {
if (opts.slideCount > 1) {
$(".center").css({
"display": "block"
});
}
});
$('.slideshow').cycle();
So according to MDN (it makes sense) the AnimationEvent has the bubble argument but how can one set it to true? Considering the event is fired from a CSS animation.
Ok, it turns out that CSS does bubble events, for example:
HTML:
<ul id="ul">
<li>
<a id="a">Some text!</a>
</li>
</ul>
CSS:
a
{
color: red;
}
a:hover
{
-webkit-animation-duration: 1s;
-webkit-animation-name: change-color;
}
#-webkit-keyframes change-color {
from
{
color: red;
}
to
{
color: blue;
}
}
JS:
var a = document.getElementById( 'a' );
var ul = document.getElementById( 'ul' );
a.addEventListener( 'webkitAnimationEnd', handleEnd );
ul.addEventListener( 'webkitAnimationEnd', handleEnd );
function handleEnd(e)
{
console.log(e);
}
You'll see two events fired. The problem I had was that I was using jQuery's bind() and this binds to a specific selector rather than listening to bubbled events (I think).
I have a content element which fades in if the user is above a certain area. The content element has a background image, which is in IE7/IE8 only a big black border instead of a gradient.
Animation code:
$(function(){
$('#TopPackets').mouseenter(function(){
jQuery('#TopPacketsContents').animate({
opacity: 1,
width: 'toggle'
}, 307, function() {
});
});
$('#TopPackets').mouseleave(function(){
jQuery('#TopPacketsContents').hide('slow');
});
});
Now the content element with the transparent background image:
<div id="TopPacketsContents" style="opacity: 1; display: none;">
<!-- content -->
</div>
CSS:
#TopPacketsContents {
background-image: url("../images/transparentBackground.png");
background-repeat: no-repeat;
height: 303px;
width: 411px;
}
I tried the high ratest answer of this thread, but I cannot set background: transparent because I have a background image!
I also tried to create a wrapper element like on this page.
HTML
<div id="TopPacketsContents">
<div class="BackgroundImageWrapper">
<!-- content -->
</div>
</div>
CSS
#TopPacketsContents {
height: 303px;
width: 411px;
}
.BackgroundImageWrapper {
background-image: url("../images/TopPacketsBackground.png");
background-repeat: no-repeat;
}
So what are my options? I could use a non transparent image only for IE7/IE8 with conditional comments (would look ugly). Should I use another animation? Should I use a hover effect instead of the animation (only for IE7/IE8)? Are there any other fixes out there?
See W3Schools on the opacity setting for CSS:
The CSS for this is: opacity=1.
IE8 and earlier: filter:alpha(opacity=100).
Seems I got this working. As I said I removed the opacity parameter:
<script type="text/javascript">
$(function(){
$('#TopPackets').mouseenter(function(){
jQuery('#TopPacketsContents').animate({
width: 'toggle'
}, 307, function() {
});
});
$('#TopPackets').mouseleave(function(){
jQuery('#TopPacketsContents').hide('slow');
});
});
</script>
New CSS with filter:
#TopPacketsContents {
width:411px;
height:303px;
background-image:url(../images/transparentBackground.png);
background-repeat: no-repeat;
/* IE hack */
background:none\9; /* Targets IE only */
filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="path/to/images/transparentBackground.png", sizingMethod="crop");
}
The following answer didn't work for me. I took my solution from this answer.
I have a div with an image in it. At the moment I use CSS3 animation to fade it off, but the performance is terrible.
I am pretty sure I should be using transitions. Problem is I cannot find one example that isn't triggered by a hover.
How can I make it so that when the page is loaded, after a delay of 2 seconds, the image/div fades in from 0%?
At the moment, as I said with animation, I have:
#-webkit-keyframes fadetime {
from {
opacity: 0;
}
50% {
opacity: 0;
}
to {
opacity: 1;
}
}
Any ideas? Thank you.
#-webkit-keyframes FadeIn {
0% {
opacity:0;
}
100% {
opacity:1;
}
}
.object {
-webkit-animation-name: FadeIn;
-webkit-animation-timing-function: ease-in;
-webkit-animation-duration: 3s;
}
Using jQuery is probably a better way to go:
<script type="text/javascript">
$(document).ready(function () {
$('#mainContent').hide();
$('#mainContent').delay(2000).fadeIn(500);
});
</script>
Where #mainContent is the div you want to fade in