html5交互式地铁线路图,HTML5 SVG城市地铁路线图动画演示

本文介绍了一个基于JavaScript实现的地铁线路选择交互案例。通过使用Babel和CoffeeScript等工具,该案例实现了平滑的按钮移动效果及触摸屏上的滑动选择功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

JavaScript

语言:

JaveScriptBabelCoffeeScript

确定

// https://uimovement.com/ui/2806/metro-line-selection/

var selPos = 0;

var moving = false;

// Function to highlight selected track

function display_track(num) {

$('.junction, body').removeClass('act1 act2 act3 act4');

$('.track, .station, .junction').removeClass('active');

if (num) {

$('.track.line' + num + ', .station.line' + num).addClass('active');

$('.junction.line' + num + ', body').addClass('act' + num);

} else {

$('.track, .station, .junction').addClass('active');

}

};

// Button moving functions

function move_buttons_left() {

if (selPos > 0) {

$.each($('.track-select'), function() {

$(this).css('left', ((parseFloat($(this).css('left')) / $('.select-container').width()) * 100 + 50) + '%');

});

selPos--;

// Display selected track

display_track(selPos || '');

};

};

function move_buttons_right() {

if (selPos < ($('.track-select').length - 1)) {

$.each($('.track-select'), function() {

$(this).css('left', ((parseFloat($(this).css('left')) / $('.select-container').width()) * 100 - 50) + '%');

});

selPos++;

// Display selected track

display_track(selPos || '');

};

};

// Mover click function

$('.mover').click(function() {

if (!moving) {

// Move left or right

if ($(this).hasClass('left')) {

move_buttons_left();

} else if ($(this).hasClass('right')) {

move_buttons_right();

};

// For timing so the user doesnt call function while the cards are moving

moving = true;

setTimeout(function() {

moving = false;

}, 400);

}

});

// Display selected track

// $('.track-select').click(function(){ display_track($(this).attr('name')); });

$(document).ready(function() {

display_track();

// For Mobile - Swipe stuff that I stole from the internet

document.getElementsByClassName('select-container')[0].addEventListener('touchstart', handleTouchStart, false);

document.getElementsByClassName('select-container')[0].addEventListener('touchmove', handleTouchMove, false);

var xDown = null;

var yDown = null;

function handleTouchStart(evt) {

xDown = evt.touches[0].clientX;

yDown = evt.touches[0].clientY;

};

function handleTouchMove(evt) {

if (!xDown || !yDown) {

return;

}

var xUp = evt.touches[0].clientX;

var yUp = evt.touches[0].clientY;

var xDiff = xDown - xUp;

var yDiff = yDown - yUp;

if (Math.abs(xDiff) > Math.abs(yDiff)) {

if (xDiff > 0) {

move_buttons_right()

} else {

move_buttons_left();

}

} else {

if (yDiff > 0) {

/* up swipe */

} else {

/* down swipe */

}

}

/* reset values */

xDown = null;

yDown = null;

};

});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值