【问题标题】:CSS & Jquery top header sliderCSS & Jquery 顶部标题滑块
【发布时间】:2019-01-29 09:36:35
【问题描述】:

我想创建一个与 website 相同的顶部面板滑块,当我查看该网站源时,我看到了所有内容,因为我复制了有助于创建它的特定代码,但我有两个问题。

屏幕截图

  1. 当我点击该选项时,我无法使我的代码可滑动。

  2. 我无法从此image 中裁剪该幻灯片菜单图像按钮。

您好,请帮帮我,我真的遇到了麻烦,如何从这个image 制作可滑动或裁剪菜单图像。

要查看原始网站的源代码在这里,网站是here

我的代码是:

#netbanking_branches {
  margin: 0 0px 0 10px;
}

.netbanking_button {
  background-position: -58px -643px;
  height: 35px;
  width: 200px;
}

#netbanking_branches,
.netbanking_button {
  float: left;
}

.netbanking_button,
.netbanking_button_up {
  background-image: url("https://corp.onlinesbi.com/personal/images/sprite_a.png") ! important;
  background-repeat: no-repeat;
}

#netbanking_popup {
  border-bottom: 5px solid #cbcbcb;
  z-index: 1000;
  left: 0px;
  top: 0px;
  background: #d9d9d9 url("https://corp.onlinesbi.com/personal/images/netbanking_repeat.png" repeat-x;
  width: 100%;
}

#netbanking_content {
  background: url("https://corp.onlinesbi.com/personal/images/netbanking_img.png") no-repeat left top;
  height: 123px;
  padding: 10px 0 0 255px;
  color: #6f6f6f;
  line-height: 20px;
}

#netbanking_content_heading {
  color: #0197c0;
  font-size: 15px;
  font-weight: bold;
  margin: 5px 0;
}

#netbanking_popup,
.product_content {
  display: none;
}

#netbanking_popup {
  position: absolute;
}

#netbanking_content_heading {
  font-size: 13px;
}
<!-- Header core info -->
<div id="netbanking_branches" class="netbanking_branches">
  <a href="" class="netbanking_button" title="Netbanking Branches" tabindex="4">&nbsp;</a>
  <div id="netbanking_popup">
    <div id="netbanking_content">
      <div id="netbanking_content_heading">
        <p>contant</p>
      </div>
    </div>
  </div>
  <!-- Header core info Ends-->

【问题讨论】:

    标签: jquery html css slide


    【解决方案1】:

    如果我理解正确,您需要做一些更改:

    1. 需要添加js代码来处理按钮上的click事件。
    2. 我稍微更改了 css 和 html,使其适合您想要的行为。
    3. 我正在使用 css3 过渡来创建“幻灯片”效果。欲了解更多信息,请阅读此post
    4. 您标记的徽标左侧的奇怪线条不是来自图像,而是来自链接(a 标签)。你放了一个空格字符,a 标签默认有text-decoration: underline,所以这条规则的线条绘制。

    const netbankingPopup = document.querySelector('#netbanking_popup');
    document.querySelector('.netbanking_button').addEventListener('click', e => {
      netbankingPopup.classList.toggle('visible');
      e.preventDefault();
    });
    body{
      margin: 0;
    }
    
    #netbanking_branches {
      text-align: center;
    }
    
    .netbanking_button {
      background-position: -58px -643px;
      height: 35px;
      width: 200px;
    }
    
    .netbanking_button {
      display: inline-block;
    }
    
    .netbanking_button,
    .netbanking_button_up {
      background-image: url("https://corp.onlinesbi.com/personal/images/sprite_a.png");
      background-repeat: no-repeat;
    }
    
    #netbanking_popup {
      background: #d9d9d9 url("https://corp.onlinesbi.com/personal/images/netbanking_repeat.png") repeat-x;
      width: 100%;
      max-height: 0;
      transition: max-height .3s ease;
      overflow: hidden;
      text-align: left;
    }
    
    #netbanking_popup.visible {
      max-height: 100px;
      border-bottom: 5px solid #cbcbcb;
    }
    
    #netbanking_popup.visible + .netbanking_button {
      background-position: -58px -590px;
    }
    
    #netbanking_content {
      background: url("https://corp.onlinesbi.com/personal/images/netbanking_img.png") no-repeat left top;
      height: 123px;
      padding: 10px 0 0 255px;
      color: #6f6f6f;
      line-height: 20px;
    }
    
    #netbanking_content_heading {
      color: #0197c0;
      font-size: 15px;
      font-weight: bold;
      margin: 5px 0;
    }
    
    .product_content {
      display: none;
    }
    
    #netbanking_content_heading {
      font-size: 13px;
    }
    <!-- Header core info -->
    <div id="netbanking_branches" class="netbanking_branches">
      <div id="netbanking_popup">
        <div id="netbanking_content">
          <div id="netbanking_content_heading">
            <p>contant</p>
          </div>
        </div>
      </div>
      <a href="" class="netbanking_button" title="Netbanking Branches" tabindex="4"></a>
    </div>
    <!-- Header core info Ends-->

    【讨论】:

    • 感谢您的回答,您所做的与我想要的一样,但仍然有 2 个问题,实际上我想要 100% 的 contant -&gt; paragraph 区域,并且想要在滑块向下箭头显示时制作错误指示符顶部箭头向下显示。
    • 刚刚更新了我的答案。注意css部分,了解它的工作原理很重要(例如floatdisplay: inline-block之间的区别)
    • 如何删除滑块左右两侧的空白,并将窗口中的修复设置为顶部。?
    • 我更新了我的答案。只需从#netbanking_branches 中删除margin 并将body margin 设置为0(默认为5px
    • 谢谢你,你真是天才,有资格投票。但是按钮没有在中心对齐,我从这张图片中删除了无用的图片,请查看https://corp.onlinesbi.com/personal/images/sprite_a.png
    【解决方案2】:

    您可以在每个元素上使用带有 onclick 事件的 jQuery 来向下滑动并显示它们。

    不要忘记导入 jQuery 库:7

    使用这个:

        <div id="netbanking_branches" class="netbanking_branches">
          <a href="" class="netbanking_button" id="netbanking_button" title="Netbanking Branches" tabindex="4"></a>
          <div id="netbanking_popup">
            <div id="netbanking_content">
              <div id="netbanking_content_heading">
                <p>contant</p>
              </div>
            </div>
          </div>
        <div id="content">
         content in your upper slider
        <div id="netbanking_button">close</div>
       </div>
        <script>
          jQuery('#netbanking_button').on('click',function(){
             $('#content').slideDown();
          });
          jQuery('#netbanking_button_close').on('click',function(){
             $('#content').slideUp();
          });
        </script>
    

    【讨论】:

    • 你的 jquery 有问题
    猜你喜欢
    • 1970-01-01
    • 2013-07-08
    • 2013-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-18
    相关资源
    最近更新 更多