在豆瓣浏览电影的时候,我们会看到每部电影都有相应的评分,这些评分可能是 8.1 ,也可能是 7.6 ,每个评分前都有5个星星表示这个评分,评分是 8 则意味着四颗橙色星星,一颗灰色星星,而评分是 8.1 就无法用一颗完整的星星表示,我用下面的方法完成这种情况
思路:写两个 div , 一个 div 里面依次排列5个灰色星星,我们叫它『灰div』,另一个 div 里面依次排列5个橙色星星,我们叫它『橙div』,『灰div』写在『橙div』前面,我们利用定位把两个 div 重叠在一起,用『橙div』覆盖『灰div』,然后控制『橙div』的宽度为评分对应的百分比,就 OK 了
具体代码
<div class="wrapper"> <div> <i class="icon">*</i> <i class="icon">*</i> <i class="icon">*</i> <i class="icon">*</i> <i class="icon">*</i> </div> <div style="width:81%"> <i class="icon star">*</i> <i class="icon star">*</i> <i class="icon star">*</i> <i class="icon star">*</i> <i class="icon star">*</i> </div></div><span class="star">8.1</span>
.wrapper { display: inline-block; position: relative; white-space: nowrap;}.wrapper > div { display: inline-block;}.wrapper > div:nth-child(1) > i { color: #ddd;}.wrapper > div:nth-child(2) { position: absolute; left: 0; z-index: 2; overflow: hidden;}.star { color: #ff6600;}
移动端页面回退下拉列表状态不一致
当我在『原页面』用下拉列表选择某选项后,页面局部刷新了,然后我点击跳转到别的页面,这时候我回退到『原页面』,发现页面回到最初状态,而下拉列表停留在选择后状态,这明显不对了。而且,上述问题出现在chrome模拟状态下,手机百度和safari有这样的问题,我在uc浏览器测试,却发现下拉列表恢复到了默认选项,也就是各个浏览器表现不近相同
解决:问题分为两部分解决,第一部分监听 window 的 pageshow 事件,来判断回退触发;第二部分,在小伙伴的细心观察下,发现虽然下拉列表显示选项是选择后状态,但是其实下拉列表的 selected 是恢复到默认状态的,所以解决方法就简单了,直接重置 selected 属性就OK了
window.addEventListener('pageshow', function (event) { $('down').find('[selected="1"]').removeAttr('selected').attr('selected', '1');});
网络连接状态
本来的初衷是获取联网状态,2G、3G、4G或wifi这样的信息, W3C 的规范中给出了一个方法来获得现在的网络状态 navigator.connection ,能够获取联网状态信息,但是兼容十分不好,不得不放弃选择其次只获取网络连接状态
一个属性, navigator.onLine ,true 表示在线, false 表示离线;两个监听事件, online 监听在线, offline 监听离线
window.addEventListener('load', function (e) { if (navigator.onLine) { /* 在线 doing... */ } else { /* 离线 doing... */ }}, false);window.addEventListener('online', function (e) { /* 在线 doing... */}, false);window.addEventListener('offline', function (e) { /* 离线 doing... */}, false);

The official account web page update cache, this thing is simple and simple, and it is complicated enough to drink a pot of it. You worked hard to update the official account article, but the user still opened the old version. Who can bear the taste? In this article, let’s take a look at the twists and turns behind this and how to solve this problem gracefully. After reading it, you can easily deal with various caching problems, allowing your users to always experience the freshest content. Let’s talk about the basics first. To put it bluntly, in order to improve access speed, the browser or server stores some static resources (such as pictures, CSS, JS) or page content. Next time you access it, you can directly retrieve it from the cache without having to download it again, and it is naturally fast. But this thing is also a double-edged sword. The new version is online,

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

This article demonstrates efficient PNG border addition to webpages using CSS. It argues that CSS offers superior performance compared to JavaScript or libraries, detailing how to adjust border width, style, and color for subtle or prominent effect

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

This article explains the HTML5 <time> element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Zend Studio 13.0.1
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version
Recommended: Win version, supports code prompts!
