简体   繁体   中英

javascript $(window).width() property not working in in Internet Explorer

I've following Div with absolute position:

<div id="target" style="height: 300px; position: absolute; top: 275px;"></div>

What I am doing is calculating the screen horizontal resolution using javascript and then using that obtained width, I am calculating the width and the left position of my "target" div as follows:

var windowWidth = $(window).width();
var targetWidth = windowWidth * 0.7;
var targetLeftPos = windowWidth * (15 / 100);
$('#target').css({ 'width': targetWidth });
$('#target').css({ 'left': targetLeftPos });

This code working perfectly in all the browsers but in IE this code is not working at all causing the target div not having width and left position style , causing all my designing to be just destructed.

Is there any way to detect the clients browser and then do the alternate code if the detected browser is IE.

Please tell me how should I detect clients browser and what alternate code should I execute for IE.

Thanks in advance.

代替$(window).width ,使用

var windowWidth = window.innerWidth;

I figure out the problem... the external jquery plugin stickyscroll.js was causing the problem. It is stopping the execution of all js on the page (happening only in IE). When I removed it, the above code working all the way accurate for IE also....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM