So I made this: http://jsfiddle.net/RaV3u/5/
...but haven't been able to figure out how to make the slides loop -- that is, when the last slide finishes, it continues from the first, and the same for the first slide going backwards.
Does anyone have an idea how to do this?
/* THUMBNAIL SLIDER IMAGES
------------------------------------------- */
.slideshow {
height: 200px;
position: relative;
overflow: hidden;
}
.images {
position: absolute;
left: 0; /* Change this value to slide */
top: 0;
height: 100%;
width: 300%;
z-index: -1; /* send this layer behind the .circle layer */
}
/* THUMBNAIL SLIDER NAVIGATION
------------------------------------------- */
.thumb-slide-nav-wrapper {
margin: 70px 15px; /* position of the nav buttons */
overflow:auto;
}
.circle-left {
/* position of the nav buttons */
float:left;
}
.circle-right {
/* position of the nav buttons */
float:right;
}
.circle {
/* nav buttons */
z-index: 1;
border-radius: 50%;
width: 60px;
height: 60px;
background: green;
}
a .circle:hover {
background: lightgrey;
}
Thanks.
Demo
In Your JavaScript Just check whether the end (first or last image) is reached before sliding it.
To get total count of images use: var tot=$(".images").find("img").length;
and use a counter variable i to check the direction of sliding and end image reached or not condition.
So here is your changed JS/JQuery:
$(document).ready(function() {
var tot=$(".images").find("img").length; //total images in slider nav
var i=0; //acts as a counter
var thumbSliderPos = $(".images").css("left");
// Detect thumbnail nav button clicks
$('#circle-left').click(function() {
//Detect if first image is reached?
if(i<=0){
i=tot-2;
$(".images").animate({
"left": "-="+(400*i),
}, 400);
//Yes Show last image
}
else
{
$(".images").animate({
left: "+=400",
}, 400);
i--;
}
});
$('#circle-right').click(function() {
//Detect if last image is reached?
if(i>=tot-2)
{
$(".images").animate({
left: "0",
}, 400);
i=0;
//Yes Show first image
}
else
{
$(".images").animate({
left: "-=400",
}, 400);
i++;
}
});
});
To make it autoSlide after page loads Here is another:
Demo
Hope it Helps you. Cheers :) !
Related
I have a very sublet keyframe animation. I'd like for it to play every single time the page has been scrolled - not just once when coming in the viewpoint. Each time the scroll is touched. All I can find is running once in viewport - which is fine, but it needs to play every time the scroll is touched in the viewport. Any ideas?
/* CSS */
.aha-section .pixels .light {
margin-top: 4px;
margin-left: 33px;
animation: slide 2s 1;
}
#keyframes slide {
from {
margin-left: 33px;
}
50% {
margin-left: 45px;
}
to {
margin-left: 33px;
}
}
You will need to use some JavaScript... then you will listen to the scroll event to do the desired function...
To trigger a animation set a class to it:
.scrolled .aha-section .pixels .light {
animation: slide 2s 1;
}
and let the javascript add this class when the event scroll happens:
document.body.className += ' scrolled';
hope it helps to show you the direction.
let animated = false;
window.addEventListener("scroll", (event) => {
animateOnScroll();
});
function animateOnScroll(){
if(animated == false){
animated = !animated;
document.body.className += ' scrolled';
setTimeout(function() {
animated = false;
document.body.classList.remove('scrolled');
}, 2000); //match whatever time set on css animation
}
}
.aha-section {
position: fixed;
}
.aha-section .pixels .light {
margin-top: 4px;
margin-left: 33px;
}
.scrolled .aha-section .pixels .light {
animation: slide 2s 1;
}
#keyframes slide {
from {
margin-left: 33px;
}
50% {
margin-left: 45px;
}
to {
margin-left: 33px;
}
}
.scroll-emulator {
height: 2500px;
}
<div class="aha-section">
<div class="pixels">
<div class="light">Light</div>
</div>
</div>
<div class="scroll-emulator"><div>
I have a large element that has multiple animated (rotating) images, and you can zoom in and out on the entire div (which changes its scale transform). However, if an image element is created while the div is zoomed out, when I zoom back in I can see that the image is very blurry, as if it the image was downscaled when the element was created. A possible workaround would be to hide & show the image every time I zoom, but that doesn't sound like the best solution.
Here's a snippet demonstrating the issue (fiddle). Click on the first link to get a blurred image (sometimes only breaks on the second click), and on the second link to get a good image.
$(".try-1").click(function() {
$(".image").remove();
$(".pos").css("transform", "scale(0.4)").append("<div class=\"image\"></div>");
setTimeout(() => {
$(".pos").css("transform", "scale(1.4)");
}, 500)
});
$(".try-2").click(function() {
$(".image").remove();
$(".pos").css("transform", "scale(1.4)").append("<div class=\"image\"></div>");
});
.clicky {
color: #00f;
cursor: pointer;
}
.clicky:hover {
text-decoration: underline;
}
.div {
position: relative;
width: 500px;
height: 500px;
background: #000;
}
.pos {
position: absolute;
left: 250px;
top: 250px;
}
#keyframes rotating-cw {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
.image {
position: absolute;
left: -150px;
top: -150px;
width: 300px;
height: 300px;
background: url(http://i.imgur.com/grJ6I3k.png);
background-size: 300px 300px;
animation: rotating-cw 30s linear infinite;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span class="clicky try-1">Create & zoom in</span> | <span class="clicky try-2">Zoom in & create</span>
<div class="div">
<div class="pos">
</div>
</div>
use this:
.pos {
-webkit-perspective: 1000;
position: absolute;
left: 250px;
top: 250px;
}
This can be solved using requestAnimationFrame but a simpler and more straightforward solution is to tell the browser to again initialize the image's container
$(".try-1").click(function() {
$(".image").remove();
$(".pos").css("transform", "scale(0.4)").append("<div class=\"image\"></div>");
setTimeout(() => {
$(".pos").css("transform", "scale(1.4)");
// Here, after we scale up the element again append
// the .image element but first remove it
$(".image").remove();
$(".pos").append("<div class=\"image\"></div>");
}, 500)
});
JsFiddle
Correct behaviour: filter: blur(); should not be applied to the flyout menu (this is shown in Edge, right-hand screenshot).
Google Chrome is ignoring -webkit-filter: none; on the flyout menu (left-hand screenshot).
CSS Code:
#nav { /* Default Navigation Style */
position: fixed;
left: -100vw; /* Ensure the Nav is hidden offscreen */
top: 0;
width: 0;
height: 100vh;
max-height: 100%;
padding: 5px;
background-color: rgba(0,0,0,0.75);
font-size: 4vmin;
overflow: hidden;
transition: left 0.5s linear, width 0.5s linear;
z-index: 999;
}
#nav.open {
left: 0;
width: 15vw;
-webkit-filter: none;
filter: none;
}
.nav-open { /* When the Menu is open, blur everything */
filter: blur(5px);
} /* This gets applied to body and header elements through JavaScript */
Javascript:
var mouseDown = false;
function showMenu() {
document.querySelector('#nav').className = 'open';
document.querySelector('body').className = 'nav-open';
document.querySelector('#header').className = 'nav-open';
document.querySelector('#nav').focus();
}
function hideMenu() {
if(mouseDown) { // Prevents the Menu from being hidden when a link is clicked inside it.
document.querySelector('#nav').focus();
mouseDown = false;
}else{ // If no link was clicked, hide the menu
document.querySelector('#nav').className = '';
document.querySelector('body').className = ''
document.querySelector('#header').className = '';
}
}
document.querySelector('a').onmousedown = function() {
mouseDown = true; // Detects if a link was clicked
}
Any ideas on a possible workaround for Chrome?
Problem found:
document.querySelector('body').className = 'nav-open';
Fix:
Replace the above line with one for each of the main DIV elements
document.querySelector('#content').className = 'nav-open';
document.querySelector('#slideshow').className = 'nav-open';
document.querySelector('#header').className = 'nav-open';
document.querySelector('#footer').className = 'nav-open';
Why?
It seems that when you use
position: fixed || absolute;
In Edge, that apparently breaks the Parent->Child relationship in the DOM, so in my first code, applying the blur to the whole of the body did NOT effect the fixed positioned #nav menu. It was no longer a child of the body element.
Google Chrome was doing what it should do.
When I enter my website and resize the browser to make it smaller and then scroll horizontally to the right, half of the nav bar is getting cut off, I want the nav bar to show all my links even if I have to scroll to the right.
Why is this happening?
here is my css:
#header{
width:100%;
}
.head{
width: 100%;
min-width: 1350px;
height: 100px;
position: fixed;
top: 0;
left: 0;
background-color:#303030;
}
nav{
width:655px;
margin-top:20px;
float:right;
border:2px solid yellow;
}
$(function(){
var shrinkHeader = 100;
$(window).scroll(function() {
var scroll = getCurrentScroll();
if ( scroll >= shrinkHeader ) {
$('.head').addClass('shrink');
$('#logo').hide();
$('#postLogo').addClass('now').show();
}
else {
$('.head').removeClass('shrink');
$('#logo').show();
$('#postLogo').addClass('now').hide();
}
});
function getCurrentScroll() {
return window.pageYOffset;
}
});
My code currently looks like this:
#keyframes lfade {
from {
opacity: 0;
margin-left: 45px;
}
to {
opacity: 1;
margin-left: 0px; //this line
}
}
Can I remove the margin-left line in the to block so the browser uses the default margin for the object I'm trying to animate instead of 0px?
It seems to work in Firefox and Opera, but I wasn't able to find any official sources.
Yeah you can but first you have to specify the original margin left in the stylsheet of what you are animating before taking it out like this :
#tag { width: 200; margin-left:45;}//you just do what you know overthere
then set your animation tags
#keyframes lfade {
from {
opacity: 0;
margin-left: 45px;
}
to {
opacity: 1;
margin-left: 0px; //this line
}
}
try this