JS : title显示和隐藏效果

这篇博客主要探讨如何使用JavaScript实现标题的显示和隐藏效果,通过简单的代码示例,介绍相关技巧。遵循知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议。
摘要由CSDN通过智能技术生成

JS

<script type="text/javascript" language="javascript">
var time;
var normar_title=document.title;
document.addEventListener('visibilitychange', function () {
   
    if (document.visibilityState == 'hidden') {
   
         clearTimeout(time);        
         document.title = '客官请留步ε=ε=ε=(゜ロ゜;)┛';
    } else {
   
        document.title = '你终于回来了(。・∀・)ノ';
        time=setTimeout(function(){
    document.title = normar_title; }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以通过监听输入框的 focus 和 blur 事件来实现获取焦点显示、失去焦点隐藏效果,具体代码如下: ```html <!DOCTYPE html> <html> <head> <title>百度输入框</title> <style> #search-box { position: relative; width: 400px; height: 30px; margin: 0 auto; margin-top: 100px; } #search-input { width: 100%; height: 100%; padding: 0 10px; font-size: 16px; border: 1px solid #ccc; border-radius: 15px; outline: none; box-sizing: border-box; } #search-suggest { position: absolute; top: 30px; left: 0; width: 400px; max-height: 200px; overflow: auto; box-sizing: border-box; border: 1px solid #ccc; border-radius: 5px; background-color: #fff; display: none; } #search-suggest ul { list-style: none; margin: 0; padding: 0; } #search-suggest li { height: 30px; line-height: 30px; padding: 0 10px; cursor: pointer; } #search-suggest li:hover { background-color: #f5f5f5; } </style> </head> <body> <div id="search-box"> <input type="text" id="search-input" placeholder="输入搜索内容"> <div id="search-suggest"></div> </div> <script> var searchInput = document.getElementById('search-input'); var searchSuggest = document.getElementById('search-suggest'); searchInput.addEventListener('focus', function() { searchSuggest.style.display = 'block'; }); searchInput.addEventListener('blur', function() { searchSuggest.style.display = 'none'; }); </script> </body> </html> ``` 通过监听输入框的 focus 和 blur 事件,当输入框获取焦点时,显示搜索建议框,当输入框失去焦点时,隐藏搜索建议框。搜索建议框使用绝对定位实现,并设置了最大高度和滚动条。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值