我在我的网站中插入了一小段 jQuery 代码,以修复左右导航图标。问题是它仅在调整 Bowser 窗口大小时才有效,但它应该在文档加载后立即放置图标...在这里您可以看到它的实际效果(匈牙利语):utravalo.com
此代码适用于我的其他网站,没有问题。我有点困惑... :)
这是jquery代码:
if (jQuery) {
/* obtain jQuery instance */
$sdv = jQuery.noConflict();
/* ensure the links look & feel consistent */
var formatLink = function (strEl) {
var pEl = $sdv(strEl);
if (pEl.length > 0) {
pEl.children().children().css('color', '#3D536C');
pEl.children().children().hover(
function () {
$sdv(this).css('color', '#444444');
}, function () {
$sdv(this).css('color', '#3D536C');
});
}
}
formatLink("#divPrev");
formatLink("#divNext");
var fnModifyNavigation = function () {
/* obtain window's width */
var w = $sdv(window).width();
var hw = (w - 1020) / 2;
if (hw > 100) {
/* we have enough space for the fixed postion links */
jQFPL($sdv("#divPrev"), 'left', 0, hw);
jQFPL($sdv("#divNext"), 'right', 0, hw);
$sdv("#divPostNav").hide();
} else {
/* not enough space for the fixed postion links */
var divNav = $sdv("#divPostNav");
if (divNav.length > 0) {
if (divNav.css('display') == 'none') {
divNav.show();
divNav.prepend(jQSPL("#divNext", "right"));
divNav.prepend(jQSPL("#divPrev", "left"));
}
}
}
}
/* jQuery Fixed Position Link */
var jQFPL = function (el, remClass, absPosPX, width) {
var pEl = el.detach();
if (pEl) {
pEl.removeClass(remClass);
eval("var objStyle = { 'position':'fixed', 'top':'250px', 'width': '" + width + "px', '" + remClass + "':'" + absPosPX + "px', 'text-align':'" + remClass + "'};");
pEl.css(objStyle);
pEl.appendTo("body");
}
}
/* jQuery Static Position Link*/
var jQSPL = function (strEl, strFloat) {
var el = $sdv(strEl).detach();
el.css('position', 'static');
el.css('width', '50%');
el.css('float', strFloat);
return el;
}
/* run position modification routine after the document is loaded */
$sdv(fnModifyNavigation);
/* handle the window's resize event and run position modification routine again */
$sdv(window).resize(fnModifyNavigation);
}
谢谢您的帮助!!