jQuery实现仿腾讯微博滑出效果的每日天气组件

作者:像素漫游

时间:2026-10-29

浏览:438

本文介绍使用jQuery 1.6.2实现仿腾讯微博风格的每日天气展示组件。当鼠标悬停时,天气内容从左向右平滑滑出,类似抽屉开启动画。文章提供了完整的HTML、CSS及jQuery代码示例,帮助开发者快速掌握该交互效果的实现方法。

文章目录

jQuery实现仿腾讯微博滑出天气效果

本文详细介绍如何使用jQuery实现一个模仿腾讯微博风格的每日天气展示功能。该示例代码可供开发者参考学习。

此示例实现了仿腾讯微博的滑出式天气展示效果。当鼠标悬停在元素上时,天气信息会从左侧向右侧平滑滑出,视觉效果类似于拉开抽屉。该动画运行流畅,主要依赖于jQuery库的支持,具体使用了1.6.2版本的jQuery插件来完成此交互功能。


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>仿腾讯微博的每日天气效果</title>
<style type="text/css">
.weather{
 width:500px;height:100px;margin:0 auto;
 position:relative;color:#fff;text-align:center;
 overflow:hidden;
}
.weather_main{
 width:99px;border-right:solid 1px #fff;
 float:left;background:#F03;text-align:center;
 position:relative;z-index:2;
}
.weather_main strong{
 line-height:100px;
}
.weather_main strong a{
 border-bottom:solid 2px #fff;cursor:pointer;
}
.alert{
 width:400px;height:100px;position:absolute;
 left:-400px;top:0;background:#F03;
}
</style>
<script src="jquery-1.6.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
 $(document).ready(function(){
  $(".weather_main").hover(function(){
   $(".alert").animate({left:"100px"},1000);
   return false;
  },function(){
   $(".alert").animate({left:"-400px"},1000);
   return false;
   })
 })
</script>
</head>
<body>
 <div class="weather">
  <div class="weather_main">
   <strong><a>深圳</a></strong>
  </div><!--weather_main-->
  <div class="alert">
   <p>如果云知道,多想凉风来做伴~</p>
 <p><a>提醒好友</a></p>
  </div>
 </div><!--weather box-->
</body>
</html>

希望本文提供的代码示例对您在jQuery程序设计方面的学习与应用有所帮助。

实用工具推荐

电子包浆

绿化、压缩、噪点和虚拟水印,自由调节做旧程度。

使用 ›
图片压缩

选择画质和输出格式,预览压缩前后的大小。

使用 ›
相关文章