$(function() { //鼠标进入的时候,其他的li标签透明度:0.5 $(".wrap li").hover(function() { $(this).siblings().stop().fadeTo(400, 0.5); }, function() { // 鼠标离开,其他li 透明度改为 1 // $(this).siblings().stop().fadeTo(400, 1); }) });用另一种方式实现
时间: 2024-01-29 15:02:02 浏览: 22
这段代码实现了当鼠标悬停在一个列表项上时,其他列表项的透明度变为0.5,当鼠标离开时,其他列表项的透明度恢复为1。可以使用以下方式实现相同的效果:
```
$(document).ready(function() {
// 找到所有的列表项
var items = $(".wrap li");
// 给每个列表项绑定鼠标进入事件
items.mouseenter(function() {
// 找到当前鼠标悬停的列表项
var currentItem = $(this);
// 让其他列表项透明度变为0.5
items.not(currentItem).stop().fadeTo(400, 0.5);
});
// 给每个列表项绑定鼠标离开事件
items.mouseleave(function() {
// 找到当前鼠标离开的列表项
var currentItem = $(this);
// 让其他列表项透明度恢复为1
items.not(currentItem).stop().fadeTo(400, 1);
});
});
```
这段代码与原代码的区别在于,它使用了 `.not()` 方法来选择除了当前列表项以外的所有列表项,并在鼠标进入和离开事件中分别使用了 `.fadeTo()` 方法来改变它们的透明度。
相关问题
将下面的jquery换成javascript代码$(function () { //4.banner旁菜单l-list $(.l-list).children(li).hover(function () { $(this).css({ backgroundColor: #ff6700 }).siblings().css({ back
document.addEventListener("DOMContentLoaded", function() {
let lList = document.querySelector(".l-list");
let liList = lList.children;
for(let i = 0; i < liList.length; i++) {
liList[i].addEventListener("mouseenter", function() {
this.style.backgroundColor = "#ff6700";
for(let j = 0; j < liList.length; j++) {
if(j != i) {
liList[j].style.backgroundColor = "";
}
}
});
liList[i].addEventListener("mouseleave", function() {
this.style.backgroundColor = "";
});
}
});
爬取https://lab.isaaclin.cn/nCoV/api/area上的数据,然后编写实时的echart的地图
好的,这是一个比较复杂的问题,需要分步骤来完成。我会尽力解答,如果有不懂的地方,可以随时提出来。
1. 爬取数据
你可以使用 Python 的 requests 库向 https://lab.isaaclin.cn/nCoV/api/area 发送 GET 请求,获取疫情数据。获取数据后,将其转换成 Python 对象,例如字典或列表,方便后续处理和操作。代码示例:
```python
import requests
import json
url = 'https://lab.isaaclin.cn/nCoV/api/area'
r = requests.get(url)
data = json.loads(r.text)
```
2. 处理数据
获取到的数据是 JSON 格式的,需要进行处理才能在地图上展示。你可以使用 Pandas 库将数据转换成 DataFrame 对象,方便进行数据清洗和分析。DataFrame 对象可以进行多种操作,例如筛选、合并、重塑等。代码示例:
```python
import pandas as pd
df = pd.DataFrame(data['results'])
df = df[['provinceName', 'currentConfirmedCount', 'confirmedCount', 'deadCount', 'curedCount', 'locationId']]
```
这段代码将 JSON 数据转换成 DataFrame 对象,并筛选出需要的列。你可以根据需要修改列名和取值范围。
3. 绘制地图
绘制地图需要使用 ECharts 库,它是一个开源的可视化库,支持多种图表类型和交互方式。你可以使用 ECharts 提供的地图组件,绘制疫情地图。代码示例:
```javascript
var myChart = echarts.init(document.getElementById('map'));
myChart.setOption({
tooltip: {
trigger: 'item',
formatter: function(params) {
return params.name + '<br />确诊人数:' + params.value;
}
},
visualMap: {
min: 0,
max: 1000,
left: 'left',
top: 'bottom',
text: ['高', '低'],
calculable: true,
inRange: {
color: ['#f5e5e5', '#ff3333']
}
},
series: [{
name: '疫情数据',
type: 'map',
map: 'china',
roam: false,
itemStyle: {
normal: {
borderWidth: 0.5,
borderColor: '#777',
areaColor: '#f5f5f5'
},
emphasis: {
borderWidth: 0.5,
borderColor: '#777',
areaColor: '#ff3333'
}
},
label: {
normal: {
show: true
},
emphasis: {
show: true
}
},
data: []
}]
});
myChart.showLoading();
$.get('https://lab.isaaclin.cn/nCoV/api/area', function(data) {
myChart.hideLoading();
myChart.setOption({
series: [{
name: '疫情数据',
type: 'map',
map: 'china',
roam: false,
itemStyle: {
normal: {
borderWidth: 0.5,
borderColor: '#777',
areaColor: '#f5f5f5'
},
emphasis: {
borderWidth: 0.5,
borderColor: '#777',
areaColor: '#ff3333'
}
},
label: {
normal: {
show: true
},
emphasis: {
show: true
}
},
data: data.results.map(function(item) {
return {
name: item.provinceShortName,
value: item.confirmedCount
}
})
}]
});
});
```
这段代码使用 ECharts 绘制地图,从 https://lab.isaaclin.cn/nCoV/api/area 获取疫情数据,并将数据展示在地图上。
4. 实时更新
为了实现实时更新,你可以使用定时器定时向数据源获取最新的疫情数据,并更新地图。代码示例:
```javascript
setInterval(function() {
$.get('https://lab.isaaclin.cn/nCoV/api/area', function(data) {
myChart.setOption({
series: [{
data: data.results.map(function(item) {
return {
name: item.provinceShortName,
value: item.confirmedCount
}
})
}]
});
});
}, 60000);
```
这段代码使用 setInterval 函数定时向数据源获取最新的疫情数据,并更新地图。你可以根据需要修改定时器的时间间隔。