Home > Web Front-end > JS Tutorial > body text

How to control js elements to display at a fixed position on the screen and monitor screen height changes_javascript skills

WBOY
Release: 2016-05-16 15:45:55
Original
1515 people have browsed it

The example in this article describes the method of js controlling elements to be displayed at a fixed position on the screen and monitoring screen height changes. Share it with everyone for your reference. The details are as follows:

//控制logo的显示位置 Begin
window.addEventListener("resize", function () {
  // 得到屏幕尺寸 (内部/外部宽度,内部/外部高度)
  changeLogoPosition();
}, false);
changeLogoPosition();
function changeLogoPosition() {
  var contentHeight = $("#main_content_div").css("height");
  var logoHeight = $("#third_party_logo").css("height");
  contentHeight = parseInt(contentHeight.replace('px', ''));
  logoHeight = parseInt(logoHeight.replace('px', ''));
  //alert('屏幕高度:'+document.body.scrollHeight+' 内容高度:'+contentHeight+' logo高度:'+logoHeight);
  if (document.body.scrollHeight - contentHeight > logoHeight) {
    document.getElementById('third_party_logo').style.position = 'absolute';
  } else {
    document.getElementById('third_party_logo').style.position = '';
  }
}
//控制logo的显示位置 End

Copy after login

I hope this article will be helpful to everyone’s JavaScript programming design.

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!