Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

A tutorial on how to achieve the effect of skin replacement with JavaScript

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains the "JavaScript to achieve the skin effect of the method tutorial", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn the "JavaScript to achieve the skin effect of the method tutorial"!

Skinning effect: click on different pictures and change the background of the corresponding page

Realization idea

1. Define a group of pictures. Each src attribute assigns the background image path.

2. Get a set of picture element objects (get pseudo array)

3. The for loop binds the click event to the picture---onclick. In the event handler, set the background image of the body element object to---the path of the image currently clicked.

4. Note: the acquisition of the body element object is---document.body,js assigns a value to the path of the background image. Pay attention to the stitching of the path---document.body.style.backgroundImage = 'url (' + this.src +')'

Code sample skinning effect * {margin: 0; padding: 0; box-sizing: border-box;} body {background: url (images/ wallpaper 1.jpg) no-repeat center top; background-size: cover } .box {overflow: hidden; width: 610px; margin: 100px auto; background-color: # fff;} .box li {width: 25%; height: 100px; list-style: none; float: left; cursor: pointer Border: 1px solid # fff;} img {width: 100%; height: 100%;}

Var pics = document.querySelector ('.box'). QuerySelectorAll ('img'); console.log (pics); for (var I = 0; I < pics.length; iTunes +) {pics [I] .onclick = function () {console.log (this.src); document.body.style.backgroundImage =' url ('+ this.src +')' }} Page effect

Thank you for your reading, the above is the content of the "JavaScript method tutorial to achieve skin change effect". After the study of this article, I believe you have a deeper understanding of the JavaScript method tutorial to achieve skin change effect, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report