[英]Jquery jumps to iframe on load
我正在建立一個使用手風琴面板作為主要內容的網站。 我將其設置為在頁面加載時打開所有面板,但是現在頁面加載完成后,它會跳轉到頁面中間的<iframe>
。 我對javascript和jquery非常陌生,任何幫助將不勝感激。 另外,使用加載需要很長時間,但是沒有加載就很快。 有沒有一種方法可以通過<iframe>
加快加載速度? 先感謝您!
這是我的頁面: http : //abigailhardindesigns.com/staging/reeves/index.html
它正在跳轉到特定的<iframe>
:
<iframe src="http://gis.cmpdd.org/madison/" width="100%" height="1000px"></iframe>
這是Jquery:
(function($) {
$(document).ready(function () {
/*-------------------- EXPANDABLE PANELS ----------------------*/
var panelspeed = 500; //panel animate speed in milliseconds
var totalpanels = 6; //total number of collapsible panels
var defaultopenpanel = 1; //leave 0 for no panel open
var accordian = false; //set panels to behave like an accordian, with one panel only ever open at once
var panelheight = new Array();
var currentpanel = defaultopenpanel;
var iconheight = parseInt($('.icon-close-open').css('height'));
var highlightopen = true;
$('.nav a').click(function() {
$($(this).attr('href')).find('.expandable-panel-heading').click();
});
//Initialise collapsible panels
function panelinit() {
for (var i=1; i<=totalpanels; i++) {
panelheight[i] = parseInt($('#cp-'+i).find('.expandable-panel-content').css('height'));
$('#cp-'+i).find('.expandable-panel-content').css('margin-top', -panelheight[i]);
$('#cp-'+i).find('.icon-close-open').css('background-position', '0px -'+iconheight+'px');
$('#cp-'+i).find('.expandable-panel-content').css('margin-top', 0);
}
}
$('.expandable-panel-heading').click(function() {
var obj = $(this).next();
var objid = parseInt($(this).parent().attr('ID').substr(3,2));
currentpanel = objid;
if (accordian == true) {
resetpanels();
}
if (parseInt(obj.css('margin-top')) <= (panelheight[objid]*-1)) {
obj.clearQueue();
obj.stop();
obj.prev().find('.icon-close-open').css('background-position', '0px -'+iconheight+'px');
obj.animate({'margin-top':0}, panelspeed);
if (highlightopen == true) {
$('#cp-'+currentpanel + ' .expandable-panel-heading').addClass('header-active');
}
} else {
obj.clearQueue();
obj.stop();
obj.prev().find('.icon-close-open').css('background-position', '0px 0px');
obj.animate({'margin-top':(panelheight[objid]*-1)}, panelspeed);
if (highlightopen == true) {
$('#cp-'+currentpanel + ' .expandable-panel-heading').removeClass('header-active');
}
}
});
function resetpanels() {
for (var i=1; i<=totalpanels; i++) {
if (currentpanel != i) {
$('#cp-'+i).find('.icon-close-open').css('background-position', '0px 0px');
$('#cp-'+i).find('.expandable-panel-content').animate({'margin-top':-panelheight[i]}, panelspeed);
if (highlightopen == true) {
$('#cp-'+i + ' .expandable-panel-heading').removeClass('header-active');
}
}
}
}
//Uncomment these lines if the expandable panels are not a fixed width and need to resize
$( window ).resize(function() {
panelinit();
});
$(window).load(function() {
panelinit();
}); //END LOAD
}); //END READY
})(jQuery);
再次感謝你!
嘗試添加$('html, body').animate({ scrollTop: 0 }, 0);
在$(document).ready(function () {
我查看了iframe,其中嵌入的頁面很大,它加載了很多javascript文件。
我建議完全不加載它,而只是在其位置顯示一個圖像,並帶有指向該站點的鏈接(或在單擊時將圖像替換為iframe)。 這樣可以消除不必要的滾動副作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.