Home > Web Front-end > HTML Tutorial > DIV CSS, how to make DIV change position according to the window size, and follow the icon displayed by a certain click_html/css_WEB-ITnose

DIV CSS, how to make DIV change position according to the window size, and follow the icon displayed by a certain click_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 12:03:27
Original
2104 people have browsed it

I have the following code at hand, which is to add a new icon function to a certain player, set up a hidden DIV and add CSS, click to display, and click elsewhere to hide.
But this DIV does not follow the icon next to the window size change, and is fixed to 1081px. Once the window is reduced, it will no longer be visible after clicking, unless the window is stretched to 1081px width, but the position is not next to the icon, it is offset
I hope he can think of the DIV of the "more" icon, regardless of Regardless of the window size, it will appear next to the "More" icon.
And I found that the "left" of the "element.style" inline style of the "More" icon's DIV also changes with the window, but mine seems to be fixed.


//调用函数把CSS样式添加到<head>段的 <style>元素中function addGlobalStyle(css) {	var head, style;	head = document.getElementsByTagName('head')[0];	if (!head) { return; }	style = document.createElement('style');	style.type = 'text/css';	style.innerHTML = css;	head.appendChild(style);}//定义CSS样式addGlobalStyle(	'.player-info .track-info .track-controls #J_woPlay {' +	'  top: 0px; right: -33px; position: absolute; cursor: pointer;' +	'}' +	'.icon-winopenPlay {' +	'  background-image: url("http://bbsdata.gztwkadokawa.com/album/201405/28/225839pgklmuagcg25gcrr.png"); background-repeat: no-repeat;' +	'}' +	'.icon-winopenPlay {' +	'  background-position: 0px -277px; width: 18px; height: 18px;' +	'}' +	'.icon-winopenPlay:hover {' +	'  background-position: -28px -277px;' +	'}' +	'.icon-OldPlay {' +	'  background-image: url("http://bbsdata.gztwkadokawa.com/album/201405/28/225839pgklmuagcg25gcrr.png"); background-repeat: no-repeat;' +	'}' +	'.icon-OldPlay {' +	'  background-position: 0px -527px;' +	'}' +	'.icon-NewPlay {' +	'  background-image: url("http://bbsdata.gztwkadokawa.com/album/201405/28/225839pgklmuagcg25gcrr.png"); background-repeat: no-repeat;' +	'}' +	'.icon-NewPlay {' +	'  background-position: 0px -545px;' +	'}' +	'.icon-ListeningPlay {' +	'  background-image: url("http://bbsdata.gztwkadokawa.com/album/201405/28/225839pgklmuagcg25gcrr.png"); background-repeat: no-repeat;' +	'}' +	'.icon-ListeningPlay {' +	'  background-position: 0px -581px;' +	'}' +	'.track-play-menu {' +	'  padding: 10px; border-radius: 4px; left: 300px; width: 140px; height: 60px; bottom: 26px; position: fixed; z-index: 1999; background-color: rgb(51, 51, 51);' +	'}' +	'.track-play-menu ul li {' +	'  height: 30px; line-height: 30px;' +	'}' +	'.track-play-menu ul li a {' +	'  border-radius: 4px; color: rgb(170, 170, 170); line-height: 30px; padding-left: 38px; text-decoration: none; display: block; position: relative;' +	'}' +	'.track-play-menu ul li a:hover {' +	'  background-color: rgb(68, 68, 68);' +	'}' +	'.track-play-menu ul li i {' +	'  left: 8px; top: 6px; width: 18px; height: 18px; position: absolute;' +	'}' +	'.track-play-menu .arrow {' +	'  left: -9px; width: 9px; height: 18px; bottom: 16px; position: absolute; background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAASCAYAAACJgPRIAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACLSURBVChThc4BDoIwDAVQONK6HUhRuQ4xRrksqP+PDsjWwU+arO3L0uYkrfd+0LeZVkSeQD/ti6yghgheCVioADnike8csHQff/hYgJXAaC1TNWeARdTj8c0X+4oHAT7QVGFEDOAdAxMqWYLBDVVAXW8JIXRYzIeIyaGOyzjnrrhzOkRMgtrWIyKXPykjhfjqVAPDAAAAAElFTkSuQmCC");' +	'}' +	'.ks-ie7 .track-play-menu .arrow {' +	'  background-image: url("http://gtms03.alicdn.com/tps/i3/T1ZNuzFrtaXXbeUgbb-9-18.png");' +	'}');//将按钮元素添加到"更多"后面$("#J_trackMore").after("<a id=J_woPlay class=icon-winopenPlay title=弹窗播放></a>");//隐藏div和显示div$(".icon-winopenPlay").click(function(e) {	$(".track-play-menu").toggle();});$("*").click(function(event) {	if (event.target.className != "icon-winopenPlay") {		$(".track-play-menu").hide();	}});//设置div内容var str = window.location.href;		var divplay = document.createElement("div");		divplay.id = "J_trackPlayMenu";		divplay.className = "track-play-menu";		divplay.style.height = "60px";		divplay.style.left = "1081px";		divplay.style.display ="none";		divplay.innerHTML = '<ul><li><a id=J_OldPlay onclick=OldPlay(); href=javascript:void(0)>' +			'<i class=icon-OldPlay></i>' +			'旧版弹窗播放' +			'</a></li><li>' +			'<a id=J_NewPlay onclick=NewPlay(); href=javascript:void(0)>' +			'<i class=icon-NewPlay></i>' +			'新版弹窗播放' +			'</a></li>' +			'</ul>' +			'<span class="arrow"></span>' +			'</div>';		document.body.insertBefore(divplay, document.body.firstChild);//设置弹窗函数$(document).ready(function(){  $("#J_OldPlay").click(function(){    var song=[];    song = str.split("");    song.splice(21,0,"s","o","n","g","/");    songurl = song.join("");    window.open(songurl,'','scrollbars=0,toolbar=0,status=0,location=0,resizable=0,menubar=0,width=754,height=557');    window.open('','_self','');    window.close();  });});$(document).ready(function(){  $("#J_NewPlay").click(function(){    window.open(str,'','scrollbars=0,toolbar=0,status=0,location=0,resizable=1,menubar=0,width=930,height=500');    window.open('','_self','');    window.close();  });});
Copy after login


Reply to discussion (solution)

First relative position: relative;, then absolute positioning position:absolute;
This way the position will not change at any resolution

First relative position position: relative;, then absolute position position: absolute;
This way the position will not change at any resolution The position will not change at all



In fact, I did my homework through special methods~ I don’t know what you said, so I used other positioning methods. I'll see if anyone else replies, if not I'll give you points

js first obtains the top and left positions of the music icon, then adds this obtained value to the width and height of the icon itself, and then assigns it to Above the left and top of the pop-up window, isn't it where the icon is and where the pop-up is?

js first obtains the top and left positions of the music icon, then adds the obtained value to the width and height of the icon itself, and then assigns the value to the left and top of the pop-up window, so that the icon is not in the Where, where did it pop up?



I used this method to overcome it myself
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