I am building a page that is employing several different javascript elements and I seem to have run into a problem I haven't before (not surprising as I am new to javascript).
I have implemented the tutorial for the JQuery Coda Slider located here: http://jqueryfordesigners.com/coda-slider-effect/.
It seems that the sliding effect works when I run it it Firefox but not Chrome or Safari. Wondering if this is a common issue and if I am missing something obvious.
To help, I am attaching the code of the page I am working on as it may help you understand the scripts I am using.
<head>
<title></title>
<link rel="stylesheet" href="stylesheets/style.css" media="screen" />
<script src="js/jquery-1.3.2.min.js" type="text/javascript"></script>
<script type="text/javascript" src="http://cloud.github.com/downloads/malsup/cycle/jquery.cycle.all.2.73.js"></script>
<script src= "js/banner.js"type="text/javascript"></script>
<script src="js/menu.js" type="text/javascript"></script>
<script src="js/jquery.localscroll-1.2.7-min.js" type="text/javascript"></script>
<script src="js/jquery.scrollTo-1.4.2-min.js" type="text/javascript"></script>
<script src="js/jquery.serialScroll-1.2.2-min.js" type="text/javascript"></script>
<script src="js/slider.js" type="text/javascript"></script>
</head>
EDIT: slider.js
// when the DOM is ready...
$(document).ready(function () {
var $panels = $('#slider .scrollContainer > div');
var $container = $('#slider .scrollContainer');
// if false, we'll float all the panels left and fix the width
// of the container
var horizontal = true;
// float the panels left if we're going horizontal
if (horizontal) {
$panels.css({
'float' : 'left',
'position' : 'relative' // IE fix to ensure overflow is hidden
});
// calculate a new width for the container (so it holds all panels)
$container.css('width', $panels[0].offsetWidth * $panels.length);
}
// collect the scroll object, at the same time apply the hidden overflow
// to remove the default scrollbars that will appear
var $scroll = $('#slider .scroll').css('overflow', 'hidden');
// apply our left + right buttons
$scroll
.before('<img class="scrollButtons left" src="images/scroll_left.png" />')
.after('<img class="scrollButtons right" src="images/scroll_right.png" />');
// handle nav selection
function selectNav() {
$(this)
.parents('ul:first')
.find('a')
.removeClass('selected')
.end()
.end()
.addClass('selected');
}
$('#slider .navigation').find('a').click(selectNav);
// go find the navigation link that has this target and select the nav
function trigger(data) {
var el = $('#slider .navigation').find('a[href$="' + data.id + '"]').get(0);
selectNav.call(el);
}
if (window.location.hash) {
trigger({ id : window.location.hash.substr(1) });
} else {
$('ul.navigation a:first').click();
}
// offset is used to move to *exactly* the right place, since I'm using
// padding on my example, I need to subtract the amount of padding to
// the offset. Try removing this to get a good idea of the effect
var offset = parseInt((horizontal ?
$container.css('paddingTop') :
$container.css('paddingLeft'))
|| 0) * -1;
var scrollOptions = {
target: $scroll, // the element that has the overflow
// can be a selector which will be relative to the target
items: $panels,
navigation: '.navigation a',
// selectors are NOT relative to document, i.e. make sure they're unique
prev: 'img.left',
next: 'img.right',
// allow the scroll effect to run both directions
axis: 'xy',
onAfter: trigger, // our final callback
offset: offset,
// duration of the sliding effect
duration: 500,
// easing - can be used with the easing plugin:
// http://gsgd.co.uk/sandbox/jquery/easing/
easing: 'swing'
};
// apply serialScroll to the slider - we chose this plugin because it
// supports// the indexed next and previous scroll along with hooking
// in to our navigation.
$('#slider').serialScroll(scrollOptions);
// now apply localScroll to hook any other arbitrary links to trigger
// the effect
$.localScroll(scrollOptions);
// finally, if the URL has a hash, move the slider in to position,
// setting the duration to 1 because I don't want it to scroll in the
// very first page load. We don't always need this, but it ensures
// the positioning is absolutely spot on when the pages loads.
scrollOptions.duration = 1;
$.localScroll.hash(scrollOptions);
});
after hours searching and debugging I found out the solution. jQuery interfears with joomla included mootools. Remove it with the following code in your index.php header:
<?php
//remove mootools.js and caption.js
$headerstuff=$this->getHeadData();
reset($headerstuff['scripts']);
foreach($headerstuff['scripts'] as $key=>$value){
unset($headerstuff['scripts'][$key]);
}
$this->setHeadData($headerstuff);
?>
Why didn't you just copy "http://jqueryfordesigners.com/demo/coda-slider.html" Its a reduction of what you need. Remember you need these:
<script src="jquery-1.2.6.js" type="text/javascript"></script>
<script src="jquery.scrollTo-1.3.3.js" type="text/javascript"></script>
<script src="jquery.localscroll-1.2.5.js" type="text/javascript" charset="utf-8"></script>
<script src="jquery.serialScroll-1.2.1.js" type="text/javascript" charset="utf-8"></script>
<script src="coda-slider.js" type="text/javascript" charset="utf-8"></script>
And the HTML should be similar (view source to find out). It works great in Chrome.
Related
live website is on this address: www.calimousineservice.com
Hi i am making this simple website and the i tried to include a sticky nav on top. everything works as expected so far the only problem is that when i scroll the Jquery acts like a slide-in-animation rather than just sticking to the top of the window right away. also since i attached this my image slider has some kind of lagging when sliding the images. i have all my script and file.js(s) attached at the bottom of the html and here are my javascript for sticky nav in addition to its uploaded js files:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="js/jquery.cycle2.min.js"></script>
<script>
function makeSticky() {
var myWindow = $(window),
myHeader = $(".navigation");
myWindow.scroll(function() {
if (myWindow.scrollTop() == 0 ) {
myHeader.removeClass("sticky-nav");
} else {
myHeader.addClass("sticky-nav");
}
});
}
$( function() {
makeSticky();
});
</script>
there is another script that will pop up a image on the right of the nav bar when scrolled down:
<script>
function hideImg() {
var myWindow = $(window),
container= $(".nhide");
myWindow.scroll(function() {
if (myWindow.scrollTop() == 0 ) {
container.addClass("nhide");
} else{
container.removeClass("nhide");
}
});
}
$( function() {
hideImg();
});
</script>
please scroll down and up few times to get the glimpse of what i am talking about here. the nav bar, when scrolled, acts like a slide-in-animation(like a css3 animation) i want to remove that. and also the problem with my slider. thank you in advance please let me know if i need to provide more of the codes.
It's fell under the slideshow. To fix it, give your navbar z-index property with value more than the slideshow's z-index.
I guess that z-index:999 can fix it!
UPDATE:
Set your navbar's transition property to 0. Because there seem that there are global selector that is used to set the transition.
Make sure that you are using the most specific selector to prevent other element's rules ruling your navbar.
Example:
#yournavbar_container .navbar {
transition: 0s;
}
Or set all values to default:
#yournavbar_container .navbar {
transition: all 0s ease 0s;
}
You can also use this:
#yournavbar_container .navbar {
transition:none;
transition-delay:0s;
transition-duration:0s;
transition-property:none;
transition-timing-function:ease;
}
I'm trying to create this parallax effect on a landing page. Also following this tutorial https://www.youtube.com/watch?v=WTZpNAbz3jg (skip to 21:00) for the jquery.
I am now creating the jquery side of the site, but I already have a js file for this site, and created a new one for the landing page(also tried to place the code on my main js file. But anyways, to test out the listener and console, i have this code.
$(window).scroll(function(){
console.log('h1')
});
Also here is the code inside my main js file
$(document).ready(function(){
$("#graphics").hide();
$("#morew").hide();
//------------landing scroll---------------//
$(window).scroll(function(){
console.log('h1')
});
//------------Toggle---------------//
$("#hideshow1").click(function(){
$("#photography").slideToggle("slow");
$("#graphics").slideUp("slow");
});
$("#hideshow2").click(function(){
$("#graphics").slideToggle("slow");
$("#photography").slideUp("slow");
});
$("#hsw").click(function(){
$("#morew").slideToggle("slow")
});
$("#hsw2").click(function(){
$("#morew").slideUp("slow")
});
//------------before and after---------------//
//------------carousel---------------//
//------------before and after functions---------------//
$(".top").css("width", "50%");
$(".ba").mousemove(function(e){
// get the mouse x (horizontal) position and offset of the div
var offset = $(this).offset();
var iTopWidth = (e.pageX - offset.left);
// set width of bottomimage div
$(this).find(".top").width(iTopWidth);
});
//-----------lightbox/fancybox js---------------//
$('.fancybox-thumbs').fancybox({
prevEffect : 'none',
nextEffect : 'none',
closeBtn : false,
arrows : false,
nextClick : true,
helpers : {
thumbs : {
width : 50,
height : 50
}
}
});
});
But apparently neither works, also here is the script link from my html
<script type="text/javascript" src="js\jquery.js"></script>
<script type="text/javascript" src="js\script2.js"></script>
<script type="text/javascript" src="js\landing.js" defer></script>
<link rel="stylesheet" href="CSS\style2.css">
I also tried placing the "landing.js" script tag before the closing html tag, and tried to add "defer", but nothing works. If anyone can help it would be much appreciated, also I'm sorry I'm just starting with java/jQuery.
BASICALLY: I just wanna know why the scroll listener wont work, I created another site, just to test it out and it works fine.
Does this do what you want it to do?
https://jsfiddle.net/6rp7g3kn/
uses window.onscroll without the need for jQuery:
window.onscroll = function(){
$("#message").text(window.scrollY);
};
Very limited script experience.
I am attempting to get a preloader to cover my images loading in a bootstrap carousel before a second script cycles through them.
This script is as far as I can get.
<!-- Preloader -->
<script type="text/javascript">
//<![CDATA[
$(window).load(function() { // makes sure the whole site is loaded
$('#status').fadeOut(); // will first fade out the loading animation
$('#preloader').delay(50).fadeOut('slow'); // will fade out the white DIV that covers the website.
$('body').delay(50).css({'overflow':'visible'});
})
//]]>
</script>
and
<!-- Script to Activate the Carousel -->
<script type="text/javascript">
$('#preloader').delay(50).fadeOut('slow', function(){
$('.carousel').carousel({
pause: "none",
interval: 500
});
});
</script>
The sequence I need is loading animation div covering images loading in "#myCarousel" > images have loaded > covering div fades out > fade out calls:
$('.carousel').carousel({
interval: 500, //changes the speed
pause: "none",
})
Images flick through and stops on final slide.
In the example above, it seems to work – the preloader works, the carousel works too but not at the expected speed; "500" is meant to be half a second. It also seems to break the pause function to, the fact pause is set to "none" seems to be ignored.
After some help from #Shikkediel the script now reads:
<script type="text/javascript">
$(window).on('load', function() {
$('#status').fadeOut()
.queue(function() {
$('#preloader').delay(50).fadeOut('slow', function() {
$('#myCarousel').attr('data-ride', 'carousel');
$('.item').first().addClass( 'active' );
$('body').delay(50).css({'overflow':'visible'});
$('.carousel').carousel({
});
});
$(this).dequeue();
});
});
</script>
– the speed and pause are now set in the data attributes, which is great to have them set in there out of the way.
However, the preloader still does not pre load the images!
This is the test I have running: http://maxsendak.com/test/pu_v2/max_page.html
This was the first draft, a bit of optimised script :
$(window).on('load', function() {
$('#status').fadeOut()
.queue(function() {
$('#preloader').delay(50).fadeOut('slow', function() {
$('#myCarousel').attr('data-ride', 'carousel');
$('.item').first().addClass('active');
$('body').delay(50).css({'overflow':'visible'});
$('.carousel').carousel({
interval: 500,
pause: 'none'
});
});
$(this).dequeue();
});
});
But it didn't quite have the expected result - the images are set as background and not detected by the onload event. I would propose preloading, appending to the document and hiding. This should cache them for the slider. Doing an Ajax call doesn't seem to fit well here :
$(document).ready(function() {
var path = 'http://www.maxsendak.com/test/pu_v2/img/people/max/';
for (var i = 1; i <= 5; i++) {
$('<img class="preload" src="' + path + i + '.jpg" alt=""/>').appendTo('body');
}
$('.preload').each(function() {
$(this).one('load', function() {
$(this).hide();
});
});
$(window).on('load', function() {
$('#status').fadeOut()
.queue(function() {
$('#preloader').delay(50).fadeOut('slow', function() {
$('#myCarousel').attr('data-ride', 'carousel');
$('.item').first().addClass('active');
$('body').delay(2500).css({'overflow':'visible'}); // after slider finishes
$('.carousel').carousel();
});
$(this).dequeue();
});
});
});
That bit of script could be left out of course if the images weren't background, the onload event should then be enough and prevent the flashing in between slides.
Minor update - according to this article Firefox can have some issues (version 37 on Windows 7 desktop at least) with the style of the preloaded images not matching that of the targeted background images. So I've added the relevant style I can see on the slider here which should be enough (also made appending the images a bit more readable) :
for (var i = 1; i <= 5; i++) {
$('<img class="preload" alt=""/>')
.attr('src', path + i + '.jpg')
.css({'height': '100%', 'position': 'relative', 'left': 0})
.appendTo('body');
}
Hope that's the final detail for a smooth cross browser functionality.
I am using JScrollPane on a div in order to scroll through it. The div contains a self wrote javascript code that fetches the last couple of posts from my tumblr feed. However, even though the scrollpane is showing fine, for some reason it doesn't scroll completely through the div. This means that when I scroll to the end of the jscroll, there is still more content below the viewable area of the div that is not showing up. I was wondering if anyone could help me figure this out..
Here's the link to the page that I am I working with:
http://prisingh.com/#recent
This is in the head part of the document:
<link type="text/css" href="css/jquery.jscrollpane.css" rel="stylesheet" media="all" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.mousewheel.js"></script>
<script type="text/javascript" src="js/jquery.jscrollpane.min.js"></script>
<script type="text/javascript" id="sourcecode">
$(function()
{
$('.scroll-pane').jScrollPane();
});
</script>
This is in the body part:
<div class="tumblr scroll-pane">
<img src="images/recenttumblr.png" style="position:fixed;">
<script type="text/javascript" src="js/tumblr.js"></script>
</div>
Here are the javascript codes that are being used:
http://www.prisingh.com/js/
EDIT: now that I have a fix for the original div load problem I was wondering how I would go about having the Jscrollpane move dynamically with the div on window resize. Everytime I resize the window, the JScrollpane remains at the same place it was in when the website was originally loaded. I have tried the code that was given with the plugin:
$(function()
{
$('.scroll-pane').each(
function()
{
$(this).jScrollPane(
{
showArrows: $(this).is('.arrow')
}
);
var api = $(this).data('jsp');
var throttleTimeout;
$(window).bind(
'resize',
function()
{
if (!throttleTimeout) {
throttleTimeout = setTimeout(
function()
{
api.reinitialise();
throttleTimeout = null;
},
50
);
}
}
);
}
)
});
This has not solved the problem, the scroll bar keeps the div at the same width it was at on the original loading of the website.
For a demonstration just visit prisingh.com/#recent and try resizing the window once the page is loaded.
Try this
$(document).ready(function() {
var $images = $(".tumblr img")
, imageCount = $images.length
, counter = 0;
$images.one("load",function(){
counter++;
if (counter == imageCount) {
$('.scroll-pane').jScrollPane();
}
}).each(function () {
if (this.complete) {
$(this).trigger("load");
}
});
});
I'm creating a gallery for a responsive lay-out - I am using jQuery Riding Carousels for the thumbnails.
When the window is re-sized to smaller than 1024px, the orientation of the carousel needs to change from vertical to horizontal ...
I'm doing it like this at present:
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#mycarousel').jcarousel({
vertical: $(window).width() > 1008,
scroll: 3,
});
});
</script>
... the JS simply hooks up a class, but it doesn't do so if you re-size the browser window by dragging it - you need to refresh the page.
Is there a way to destroy the script and re-initialize it on the fly?
Please check Working exmpale: http://codebins.com/bin/4ldqpba/1/Jcarousel%20vertical%20on%20resize
Tested in all browsers and works perfectly fine. bounty is mine :)
In the example i have give threshold widht 350 you can test it by resizing the result pane and as soon as you start havin horizontal scroll bar it will converted to vertical.
1 possible issue depending on your requirement is if you ahve any handlers on images they will be gone after changing display way. the solution for it is wrap your #mycarousel in a div and use Jquery delegate to handle events on the wrapper so no issue with events also.
Let me know if you come under this situation.
Following code is exactly as per your need.
When the window is re-sized to smaller than 1024px, the orientation of the carousel needs to change from vertical to horizontal .
which is revers form the example as for me it makes more sense if width is less make it vertical.
jQuery(document).ready(function() {
var widthCheck = 1008;
var resizeTimer = null,
verticalFlg = $(window).width() > widthCheck;
var obj = jQuery('#mycarousel').clone();
$('#mycarousel').jcarousel({
vertical: verticalFlg,
scroll: 2
});
jQuery(window).resize(function() {
resizeTimer && clearTimeout(resizeTimer); // Cleraring old timer to avoid unwanted resize calls.
resizeTimer = setTimeout(function() {
var flg = ($(window).width() > widthCheck);
if (verticalFlg != flg) {
verticalFlg = flg;
$('#mycarousel').closest(".jcarousel-skin-tango").replaceWith($(obj).clone());
$('#mycarousel').jcarousel({
vertical: verticalFlg,
scroll: 2
});
}
}, 200);
});
})
Or you can look at the source. I'm guessing you are using version 0.2
Looking at the source
https://github.com/jsor/jcarousel/blob/0.2/lib/jquery.jcarousel.js
we can see that there are two lines (80 and 81) which are only done in object init. Those lines are
this.wh = !this.options.vertical ? 'width' : 'height';
this.lt = !this.options.vertical ? (this.options.rtl ? 'right' : 'left') : 'top';
also this line at 149
if (!this.options.vertical && this.options.rtl) {
this.container.addClass('jcarousel-direction-rtl').attr('dir', 'rtl');
}
It might be if you add those to the callback you will get better results.
You could also try version 0.3 of the plugin.
Prior answer:
Can't test it myself right now, but try this:
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#mycarousel').jcarousel({
vertical: $(window).width() > 1008,
scroll: 3,
reloadCallback: function () {
this.options.vertical = $(window).width() > 1008;
},
});
});
</script>
<script type="text/javascript">
jQuery(document).ready(function() {
var sizeCheck = function() {
return $(window).outerWidth() >= 1024
}
jQuery('#mycarousel').jcarousel({
vertical: sizeCheck(),
scroll: 3,
});
var jCarousel = jQuery('#mycarousel').data('jcarousel');
window.onresize = function() {
jCarousel.options.vertical = sizeCheck(); // maybe you have to access the option through jCarousel.plugin.options.vertical
jCarousel.reset();
}
});
</script>
Maybe this works.
I haven't tested the following code, but I am fairly sure the following code should work:
<script type="text/javascript">
var carousel;
jQuery(window).resize(function() {
if(carousel !== undefined) carousel.destroy();
carousel = jQuery('#mycarousel').jcarousel({
vertical: $(window).width() > 1008,
scroll: 3,
});
});
</script>
or even better something along the lines of:
<script type="text/javascript">
var carousel;
jQuery(document).ready(function() {
carousel = jQuery('#mycarousel').jcarousel({
vertical: $(window).width() > 1008,
scroll: 3,
});
});
jQuery(window).resize(function() {
//NOT SURE WHICH OF THE BELOW LINES WOULD WORK, try both and check which works
carousel.options.vertical = $(window).width() > 1008;
carousel.vertical = $(window).width() > 1008;
carousel.reload();
});
</script>
If it does not, you should add a console.log(carousel) to your code and check out what the prototype is of the outputted value (check F12). There should be something along the lines of destroy (or alternatively check console.log($.jcarousel())).