小程式實現錨點定位

2022-09-09 07:24:10 字數 1699 閱讀 2907

在小程式中要實現錨點定位,需要使用到元件scroll-view

需要用到的是scroll-into-view這條屬性,這條屬性的官網解釋是這樣的:

scroll-into-viewstring

值應為某子元素id(id不能以數字開頭)。設定哪個方向可滾動,則在哪個方向滾動到該元素

於是乎,我們只需要給scroll-view內要跳轉的view設定上id,然後給scroll-into-view傳入要跳轉的viewid就行了

*注意:賦值時不能用等號=賦值,要使用 this.setdata() 賦值,否則重複賦相同的值時不會跳轉

以下是原始碼(和**片段的一樣)

wxml

<

view

class

="btn_jump"

>

<

view

class

='btn_item'

bindtap

='jumpto'

data-opt

="item0"

>toitem0

view

>

<

view

class

='btn_item'

bindtap

='jumpto'

data-opt

="item11"

>toitem11

view

>

<

view

class

='btn_item'

bindtap

='jumpto'

data-opt

="item29"

>toitem29

view

>

view

>

<

scroll-view

class

="jump_list"

scroll-into-view

="}"

scroll-y

="true"

scroll-with-animation

="true"

>

<

view

wx:for

="}"

wx:key

="}"

id="item}"

class

="list_item"

>}

view

>

scroll-view

>

wxs

page(,

onload: function () ,

jumpto: function (e) )

}})

wxss

page 

.btn_jump

.btn_jump .btn_item

.jump_list

.list_item

.list_item:nth-of-type(even)

vue element ui 實現錨點定位

你好!這是你第一次使用markdown編輯器所展示的歡迎頁。如果你想學習如何使用markdown編輯器,可以仔細閱讀這篇文章,了解一下markdown的基本語法知識。20 3 導航選擇事件 default active activestep select jump for item,index in...

js錨點定位

最好是name和id都是st。避免有些特殊情況 普通定位方式是在位址後面加上 st即可,現想通過js實現定位,如下 window.location.hash st 非js形式 zkm hxy 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 zkm b ...

jQuery錨點定位

一 錨點鏈結 href jump 點我進行跳轉a id jump 跳轉到這裡了h2 1.關於 在頁面的製作中,的符號很常見,並且具有通用性。基本上,其表示的含義是 id 選擇符。例如 在 css 中 header 就表示 id 為 header 的標籤的樣式如何 在 jquery 中,header ...