更新窗口大小变量的问题
issue updating variable on window resize
我对浏览器窗口的大小有一个条件,但我的变量"windowsize"没有得到更新,只有在文档加载的值是一个考虑。我做错了什么,我需要一个全局变量吗?
我有:
jQuery(function(){
jcf.customForms.replaceAll();
initCarousel();
initCycleCarousel();
initSlideShow();
initOpenClose();
initAccordion();
jQuery('input, textarea').placeholder();
.....
...
});
.....
...
// open-close init
function initOpenClose() {
var $window = $(window);
var windowsize = $window.width();
$(window).resize(function() {
windowsize = $window.width();
});
if (windowsize > 1200) {
//if the window is greater than 1200px wide then..
jQuery('#nav > ul > li').openClose({
activeClass: 'active',
opener: '> a',
slider: '.drop-container',
animSpeed: 200,
event: 'over',
effect: 'slideAlt'
});
}
if (windowsize < 1200) {
//if the window is greater than 1200px wide then..
jQuery('#nav > ul > li').openClose({
activeClass: 'active',
opener: '> a',
slider: '.drop-container',
animSpeed: 400,
event: 'click',
effect: 'slideAlt'
});
}
});
}
Try with
jQuery(function(){
updateContainer(); // Initial load call to check it did not require resize
});
$(window).resize(function () {
updateContainer(); // If Resize happens call to check
});
function updateContainer() {
var windowsize = $(window).width();
if (windowsize > 1200) {
//if the window is greater than 1200px wide then..
jQuery('#nav > ul > li').openClose({
activeClass: 'active',
opener: '> a',
slider: '.drop-container',
animSpeed: 200,
event: 'over',
effect: 'slideAlt'
});
}
else
{
jQuery('#nav > ul > li').openClose({
activeClass: 'active',
opener: '> a',
slider: '.drop-container',
animSpeed: 400,
event: 'click',
effect: 'slideAlt'
});
}
}
试一下,
function initOpenClose()
{
var $window = $(window);
var windowsize = $window.width();
updateWindow();
$(window).resize(function() {
windowsize = $window.width();
updateWindow();
});
function updateWindow()
{
if (windowsize > 1200)
{
//if the window is greater than 1200px wide then..
jQuery('#nav > ul > li').openClose({
activeClass: 'active',
opener: '> a',
slider: '.drop-container',
animSpeed: 200,
event: 'over',
effect: 'slideAlt'
});
}
else if (windowsize < 1200)
{
//if the window is greater than 1200px wide then..
jQuery('#nav > ul > li').openClose({
activeClass: 'active',
opener: '> a',
slider: '.drop-container',
animSpeed: 400,
event: 'click',
effect: 'slideAlt'
});
}
}
}
相关文章:
- 将PHP变量传递给jQuery时遇到问题
- 参数变量出现ngTable指令问题
- 为变量分配多个nodejs导出返回值时出现问题
- 如何处理流星变量&对miniMongo有问题
- Jquery变量类型问题
- 带有.css()串联问题的jQuery变量
- JavaScript变量引用数组时出现问题
- 将一个php变量从js传递到php,并返回内容问题
- 简单的变量问题
- 可以't在quizz页面范围问题上用最终分数更新变量
- array_push平面数组问题-需要能够向数组中添加多个变量
- 尝试将变量传递到对象中时的作用域问题'的方法构造函数
- Javascript函数变量传递语法问题
- 访问带有变量的Object元素时出现问题
- 将 Ajax 数据分配给全局变量时出现问题
- JavaScript/jQuery中的基本数学问题-变量记忆值
- 简单的jQuery变量问题-变量冲突
- Javascript作用域问题:变量未被识别
- Javascript作用域问题-变量未定义
- 目标转换问题-变量修改