


CSS Tutorial (8) A brief introduction to the use of CSS combined with JS
8. Briefly introduce the use of CSS combined with JS (for event actions)
Using CSS combined with javascript can create many cooler dynamic page effects. In this tutorial Finally, I will give you a brief introduction to the application of CSS and JS. First, we need to understand the concepts of events and actions. In client-side scripting, javascript obtains interaction with the user by responding to events. For example, when the user clicks a button or moves the mouse on a certain text, a click event or mouse movement event is triggered. By responding to these events, specific functions can be completed (for example, clicking a button to pop up a dialog box, the text changes color after the mouse moves over it, etc.). Several common events are introduced below (more events are used, please check the relevant information):
onClick: Mouse click event. (It occurs when the mouse is pressed and then released.)
onDblClick: Mouse double-click event. (Refers to the mouse being pressed quickly, released, and pressed again.)
onMouseDown: Mouse press event. (Occurs when the mouse is pressed.)
onMouseUp: Mouse release event. (Refers to the mouse from the pressed state to the bounced state.)
onMouseMove: Mouse move event. (Refers to moving the mouse on a specific element.) onMouseOver: Mouse over event. (It means that it occurs when the pointer moves from the outside world to the element.)
onMouseOut: The mouse leaves event. (Occurs when the mouse leaves a specific element.)
onLoad: Loading event. (Occurs when the image or page has finished loading.)
onUnload: Unload event. (Occurs when a visitor leaves the page.)
onScroll: Scroll bar scroll event. (Occurs when a visitor uses the scroll to move up or down.)
After we have the event, we add actions to the event. Here we only talk about the action of changing the custom style of the current element. We can use this method to set two custom CSS styles first. The object originally calls the first style, and when a mouse event occurs, the object is applied to the second CSS. Style, and the mouse effect produced, see the example below.
Insert an image into the web page, customize a ".out" style, and use the gray filter to make the image black and white:
Apply this custom style to the image. When previewing the image in the browser, it becomes black and white. We define another style ".over". This style has no content and is an empty style. The style sheet code is as follows:
Then add "onMouseOver="this.className='over'" onMouseOut="this.className='out'"" to the image tag (IMG), It means that when the mouse passes over, the picture is in the over style, that is, a normal color image; when the mouse leaves, the picture is in the out style, that is, a black and white image. oMouseOver and onMouseOut are mouse events. this.className="..." means that the class name of the current object is.... Be careful not to write the wrong case. JS is very sensitive to case.
In this way, the effect is completed. After saving, open it in the browser. The image is black and white. When the mouse moves up, the image becomes color. When the mouse leaves, the image changes back to black and white. As long as you use your imagination, you can also create many beautiful mouse effects through this.className method.
The above is the detailed content of CSS Tutorial (8) A brief introduction to the use of CSS combined with JS. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-
