Home > Web Front-end > JS Tutorial > js code for floating div adaptive center display_javascript skills

js code for floating div adaptive center display_javascript skills

WBOY
Release: 2016-05-16 17:07:39
Original
1178 people have browsed it

When the div is floating and the browser window changes, it cannot be displayed in the center (because when floating, the left or right value is usually set)

You can first use jquery to get the width of the surrounding div that changes with the browser (plus listening events)

After

, get the width of the div. For example:

Copy the code The code is as follows:

function autoWidth(){

var bW = $(".call_man").width();//Peripheral div
var popWidth = (bW-150)/2 // (150 is the width of the div)
$( ".rts").css("left",popWidth); //Assign the obtained value to the div, which is the distance between the div and the left

}

autoWidth();
window.onresize = autoWidth;//Listening events

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template