我已经为我的网页创建了响应性设计。
对于我的滑块功能,我使用javascript进行响应性设计。
这是我的代码:
<script type="text/javascript">
$(document).ready(function() {
initSlider();
});
function isMobile() {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera
Mini/i.test(navigator.userAgent);
}
$( window ).resize(function() {
if (!isMobile()) {
initSlider();
window.location.href = window.location.href;
}
});
function initSlider()
{
if ($( window ).width() < 1024 && $( window ).width() > 922)
{
});
}
else if ($( window ).width() < 921 && $( window ).width() > 771)
{
});
}
else if ($( window ).width() < 770 && $( window ).width() > 568)
{
});
}
else if ($( window ).width() < 569 && $( window ).width() > 361)
{
});
}
else if ($( window ).width() < 360 && $( window ).width() > 331)
{
});
}
else if ($( window ).width() < 330 && $( window ).width() > 250)
{
});
}
else
{
});
}
}
</script>当我运行这段代码时,我得到了响应性设计,但是..。每次刷新页面时都会自动刷新。
因此,我需要删除具有相同响应性设计功能的调整大小功能。
我可以知道,是否有可能避免调整功能或克服这个更新的问题(每次)在我的网页?
注意:-我不能使用这个特殊的滑块响应设计。
发布于 2015-09-02 14:19:19
你可以试着定制这个
jQuery(document).ready(function($) {
if(window.innerWidth<800) {
$(".red").css("background","grey");
}
$(window).resize(function(){
if(window.innerWidth<800) {
$(".red").css("background","grey");
$("div.dropdown").find("#stores").removeAttr("data-toggle");
} else if(window.innerWidth>800) {
$(".red").css("background","red");
$("div.dropdown").find("#stores").attr("data-toggle","dropdown");
}
});
});来源:https://css-tricks.com/forums/topic/jquery-window-resize-fires-only-once/
https://stackoverflow.com/questions/31367026
复制相似问题