jquery首次运行加载问题,刷新后工作正常
我有一个问题,第一次加载文件时,脚本似乎没有完全加载(在清除缓存和cookies之后)。再次刷新页面会使脚本运行良好。每次我清除缓存时都会发生这种情况,所以基本上它不会在第一次运行时加载 我不知道如何验证Jquery是否没有产生不必要的问题。jquery首次运行加载问题,刷新后工作正常,jquery,Jquery,我有一个问题,第一次加载文件时,脚本似乎没有完全加载(在清除缓存和cookies之后)。再次刷新页面会使脚本运行良好。每次我清除缓存时都会发生这种情况,所以基本上它不会在第一次运行时加载 我不知道如何验证Jquery是否没有产生不必要的问题。 jQuery(文档).ready(函数($){ $(窗口)。加载(函数(){ var-fitem=0; var-litem=0; var-m=0; 函数mycarousel_initCallback(carousel){ jQuery('.product
jQuery(文档).ready(函数($){
$(窗口)。加载(函数(){
var-fitem=0;
var-litem=0;
var-m=0;
函数mycarousel_initCallback(carousel){
jQuery('.productbox').bind('click',function(){
净间隔(pt);
净间隔(nt);
$('#mycarousel prevpause').hide();
$(“#mycarousel下一个用途”).hide();
$(“#下一步”).show();
$('#prev').show();
var clickedId=jQuery(this.parent().attr('jcarouselindex');
var totaldiff=0;
console.log(单击EDID+“==>”+mitem);
如果(单击EDID==mitem){
var c_buy=jQuery(this.parent().attr('data-byitnow');
//警报(“as”+c_购买);
窗口。打开(c_buy,“_blank”);
window.focus();
//window.open=c_购买;
}
如果(单击EDID>斜接){
totaldiff=单击edid-mitem;
//console.log('clickedId'+totaldiff);
如果(总差异>0){
carousel.stopAuto();
carousel.options.scroll=totaldiff;
carousel.next();
}
}否则{
totaldiff=mitem—单击EDID;
如果(总差异>0){
carousel.stopAuto();
carousel.options.scroll=totaldiff;
上一个转盘();
}
}
返回false;
});
jQuery('.jcarousel滚动选择').bind('change',function(){
carousel.options.scroll=jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
返回false;
});
jQuery(“#mycarousel next”).bind('click',function(){
$('#mycarousel prevpause').hide();
$(“#mycarousel下一个用途”).hide();
$(“#下一步”).show();
$('#prev').show();
净间隔(pt);
净间隔(nt);
carousel.stopAuto();
carousel.options.scroll=5;
carousel.next();
返回false;
});
jQuery('#mycarousel prev').bind('click',function(){
$('#mycarousel prevpause').hide();
$(“#mycarousel下一个用途”).hide();
$(“#下一步”).show();
$('#prev').show();
净间隔(pt);
净间隔(nt);
carousel.stopAuto();
carousel.options.scroll=5;
上一个转盘();
返回false;
});
jQuery('#mycarousel prevause').bind('click',function(){
净间隔(pt);
净间隔(nt);
$('#prev').show();
carousel.stopAuto();
$(this.hide();
$(“#mycarousel下一个用途”).hide();
返回false;
});
jQuery(“#mycarousel nextpause”).bind('click',function(){
净间隔(pt);
净间隔(nt);
$(“#下一步”).show();
carousel.stopAuto();
$(this.hide();
$('#mycarousel prevpause').hide();
返回false;
});
jQuery('#prev').bind('click',function(){
$('#mycarousel prevpause').show();
$(“#mycarousel下一个用途”).hide();
$(“#下一步”).show();
carousel.stopAuto();
继续上一步(旋转木马);
$(this.hide();
返回false;
});
jQuery(“#next”).bind('click',function(){
$(“#mycarousel nextpause”).show();
$('#mycarousel prevpause').hide();
$('#prev').show();
carousel.stopAuto();
继续下一步(旋转木马);
$(this.hide();
返回false;
});
};
变量nt;
var-pt;
功能继续下一步(旋转木马){
净间隔(pt);
nt=设置间隔(函数(){
carousel.options.scroll=1;
上一个转盘();
}, 2000);
}
功能继续上一步(旋转木马){
净间隔(nt);
pt=设置间隔(函数(){
carousel.options.scroll=1;
carousel.next();
}, 2000);
}
函数mycarousel_reloadCallback(carousel){
//console.log('Carousel重载'+fitem+“==>”+litem);
makeCenterActive();
};
/**
*这是接收通知的回调函数
*当一个项目成为可见范围内的第一个项目时。
*/
函数mycarousel_itemFirstInCallback(旋转木马、项目、idx、状态){
//log('Item#'+idx+'现在是第一个项');
fitem=idx;
};
/**
*这是接收通知的回调函数
*当一个项目成为可见范围内的第一个项目时。
*/
函数mycarousel_itemLastInCallback(旋转木马、项目、idx、状态){
//log('Item#'+idx+'现在是最后一项');
litem=idx;
makeCenterActive(旋转木马);
};
功能makeCenterActive(旋转木马){
//console.log('Carousel重载'+fitem+“==>”+litem);
mitem=((litem-fitem)/2)+fitem;
var middleItemId=$('.jcarousel item-'+mitem+'.attr('id');
//console.log('middleitem'+mitem+“==>”+middleItemId);
$('.activeBox')。每个(函数(){
//动画({height:“75px”,width:“75px”,marginTop:“0px”},'200')。removeClass('activeBox');
$(this.removeClass('activeBox');
//$(此).trans
jQuery(document).ready(function ($) {
$(window).load(function () {
var fitem = 0;
var litem = 0;
var mitem = 0;
function mycarousel_initCallback(carousel) {
jQuery('.productbox').bind('click', function () {
clearInterval(pt);
clearInterval(nt);
$('#mycarousel-prevpause').hide();
$('#mycarousel-nextpause').hide();
$('#next').show();
$('#prev').show();
var clickedId = jQuery(this).parent().attr('jcarouselindex');
var totaldiff = 0;
console.log(clickedId + "==>" + mitem);
if (clickedId == mitem) {
var c_buy = jQuery(this).parent().attr('data-byitnow');
//alert("as"+c_buy);
window.open(c_buy, '_blank');
window.focus();
//window.open =c_buy;
}
if (clickedId > mitem) {
totaldiff = clickedId - mitem;
//console.log('clickedId '+totaldiff);
if (totaldiff > 0) {
carousel.stopAuto();
carousel.options.scroll = totaldiff;
carousel.next();
}
} else {
totaldiff = mitem - clickedId;
if (totaldiff > 0) {
carousel.stopAuto();
carousel.options.scroll = totaldiff;
carousel.prev();
}
}
return false;
});
jQuery('.jcarousel-scroll select').bind('change', function () {
carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
return false;
});
jQuery('#mycarousel-next').bind('click', function () {
$('#mycarousel-prevpause').hide();
$('#mycarousel-nextpause').hide();
$('#next').show();
$('#prev').show();
clearInterval(pt);
clearInterval(nt);
carousel.stopAuto();
carousel.options.scroll = 5;
carousel.next();
return false;
});
jQuery('#mycarousel-prev').bind('click', function () {
$('#mycarousel-prevpause').hide();
$('#mycarousel-nextpause').hide();
$('#next').show();
$('#prev').show();
clearInterval(pt);
clearInterval(nt);
carousel.stopAuto();
carousel.options.scroll = 5;
carousel.prev();
return false;
});
jQuery('#mycarousel-prevpause').bind('click', function () {
clearInterval(pt);
clearInterval(nt);
$('#prev').show();
carousel.stopAuto();
$(this).hide();
$('#mycarousel-nextpause').hide();
return false;
});
jQuery('#mycarousel-nextpause').bind('click', function () {
clearInterval(pt);
clearInterval(nt);
$('#next').show();
carousel.stopAuto();
$(this).hide();
$('#mycarousel-prevpause').hide();
return false;
});
jQuery('#prev').bind('click', function () {
$('#mycarousel-prevpause').show();
$('#mycarousel-nextpause').hide();
$('#next').show();
carousel.stopAuto();
continue_prev(carousel);
$(this).hide();
return false;
});
jQuery('#next').bind('click', function () {
$('#mycarousel-nextpause').show();
$('#mycarousel-prevpause').hide();
$('#prev').show();
carousel.stopAuto();
continue_next(carousel);
$(this).hide();
return false;
});
};
var nt;
var pt;
function continue_next(carousel) {
clearInterval(pt);
nt = setInterval(function () {
carousel.options.scroll = 1;
carousel.prev();
}, 2000);
}
function continue_prev(carousel) {
clearInterval(nt);
pt = setInterval(function () {
carousel.options.scroll = 1;
carousel.next();
}, 2000);
}
function mycarousel_reloadCallback(carousel) {
//console.log('Carousel reloaded'+fitem+"==>"+litem);
makeCenterActive();
};
/**
* This is the callback function which receives notification
* when an item becomes the first one in the visible range.
*/
function mycarousel_itemFirstInCallback(carousel, item, idx, state) {
//console.log('Item #' + idx + ' is now the first item');
fitem = idx;
};
/**
* This is the callback function which receives notification
* when an item becomes the first one in the visible range.
*/
function mycarousel_itemLastInCallback(carousel, item, idx, state) {
//console.log('Item #' + idx + ' is now the last item');
litem = idx;
makeCenterActive(carousel);
};
function makeCenterActive(carousel) {
//console.log('Carousel reloaded'+fitem+"==>"+litem);
mitem = ((litem - fitem) / 2) + fitem;
var middleItemId = $('.jcarousel-item-' + mitem + '').attr('id');
//console.log('Middle Item'+mitem+"==>"+middleItemId);
$('.activeBox').each(function () {
//$(this).animate({height: "75px",width:"75px",marginTop:"0px"}, '200').removeClass('activeBox');
$(this).removeClass('activeBox');
//$(this).transition({ scale: 1 });
$(this).transition({
height: "109px",
width: "135px",
marginTop: "0px"
});
$(this).children().children('img').transition({
"max-width": "105px",
"max-height": "105px"
});
});
$('.jcarousel-item-' + mitem + '').each(function () {
//$(this).animate({height: "98px",width:"89px",marginTop:"-10px",marginLeft:"0px"}, '200').addClass('activeBox');
//$(this).animate({width: "89px !important", height: "105px !important"}, 'slow');
$(this).addClass('activeBox');
//$(this).transition({ scale: 1.3 });
$(this).transition({
height: "140px",
width: "140px",
marginTop: "-17px",
marginLeft: "0px"
});
$(this).children().children('img').transition({
"max-width": "105px",
"max-height": "105px"
});
});
var c_time = $('#' + middleItemId + '').attr('data-timeremain');
var c_buy = $('#' + middleItemId + '').attr('data-byitnow');
var c_price = $('#' + middleItemId + '').attr('data-price');
$('#timeremain').html('Current' + c_time);
$('#byitnow').html('<a href="' + c_buy + '">Price :</a>');
$('#price').html(c_price);
//carousel.reload();
}
// Ride the carousel...
jQuery(document).ready(function () {
jQuery("#mycarousel").jcarousel({
scroll: 1,
auto: 1,
wrap: 'circular',
initCallback: mycarousel_initCallback,
reloadCallback: mycarousel_reloadCallback,
itemFirstInCallback: mycarousel_itemFirstInCallback,
itemLastInCallback: mycarousel_itemLastInCallback,
// This tells jCarousel NOT to autobuild prev/next buttons
buttonNextHTML: null,
buttonPrevHTML: null
});
});
})
});
$(window).load(function(){
// code part 1 here ..
jQuery(document).ready(function (){
// code part 2 here ..
});
});
jQuery(document).ready(function(){
// code part 1 here ..
// code part 2 here ..
});
jQuery(document).ready(function() {
...
});