Ying_Yong_Ke_Xue_Cheng_Da_Ping/publish/data/weather.js

103 lines
2.9 KiB
JavaScript
Raw Permalink Normal View History

2024-07-16 10:20:26 +08:00
// 天气组件交互
//晴天
$('#weather-01').click(function () {
ue4("setWeather", {"TypeCode": '001'})
})
// 多云
$('#weather-02').click(function () {
ue4("setWeather", {"TypeCode": '002'})
})
//雨天
$('#weather-03').click(function () {
ue4("setWeather", {"TypeCode": '003'})
})
//雪天
$('#weather-04').click(function () {
ue4("setWeather", {"TypeCode": '004'})
})
let animateWeatcherLock = true;
let weatherControlButt = $(".weather-open")
let weatherBox = $('#weather-box')
weatherControlButt.click(function () {
if (animateWeatcherLock) {
animateWeatcherLock = false
let isOpen = $('.weather-box').css('bottom')
if (isOpen === '0px') {
weatherBox.animate({bottom: -500 + 'px',}, 500);
$("#weather-open1").fadeIn()
$("#weather-open2").fadeOut()
} else {
weatherBox.animate({bottom: 0 + 'px',}, 500);
$("#weather-open2").fadeIn()
$("#weather-open1").fadeOut()
}
animateWeatcherLock = true
}
})
// 天气滑块锁
let canMove = false
let weather_slide = $('#weather-slide')
let old_left;
let old_position_left;
weather_slide.mousedown(function (event) {
//获取鼠标按下的时候左侧偏移量和上侧偏移量
old_left = event.pageX;//左侧偏移量
//获取鼠标的位置
old_position_left = $(this).position().left;
canMove = true
mouseMoveHandler()
});
// 天气滑块操作
function mouseMoveHandler() {
//鼠标移动
$(document).mousemove(function (event) {
if (!canMove) {
return false
}
var new_left = event.pageX;//新的鼠标左侧偏移量
//计算发生改变的偏移量是多少
var chang_x = new_left - old_left;
//计算出现在的位置是多少
var new_position_left = old_position_left + chang_x;
if (new_position_left > 220 - weather_slide.width()) {
new_position_left = 220 - weather_slide.width();
}
if (new_position_left < 0) {//左边的偏移量小于0的时候设置 左边的位置为0
new_position_left = 0;
}
weather_slide.css({
left: new_position_left + 'px',
})
let res = parseInt(new_position_left / (220 - weather_slide.width()) * 1400) + 1000
res = (Array(4).join('0') + res).slice(-4)
console.log(res)
ue4("setTime", {"TimeCode": res});
});
$(document).mouseup(function () {
canMove = false
$(document).off("mousemove");
})
}
//获取当前ue4的时间 类型0-2400
function getUe4Time(e) {
let _time = e.time
if (_time > 2400) {
_time = 2400
}
if (_time < 0) {
_time = 0
}
let left = parseInt(_time / 2400 * 220)
weather_slide.css('left', left + 'px')
}
getUe4Time({time: 1200})
//ue4调用js 未使用,无返回值
ue.interface.setFPS = function (fps) {
}