# Linked sliders (title padding)

**URL:** https://talk.observablehq.com/t/linked-sliders-title-padding/973
**Category:** Help
**Created:** [July 11, 2018, 8:08pm UTC](https://talk.observablehq.com/t/linked-sliders-title-padding/973 "2018-07-11T20:08:10Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![kelleyvanevert](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/kelleyvanevert/32/169_2.png) [@kelleyvanevert](https://talk.observablehq.com/u/kelleyvanevert)
#### Post date: [July 11, 2018, 8:08pm UTC](https://talk.observablehq.com/t/linked-sliders-title-padding/973/1 "2018-07-11T20:08:10Z")

</div>

I’m so sure I’ve seen this done before, but I can’t find it or figure it out myself:

I want to have multiple input sliders that act on the same underlying value. I.e., I have some `viewof N = slider(...)`, and then I want to have another, but such that they both update each other accordingly.

If I just do:

```javascript
M = {
  const input = slider(...);
  (viewof N).addEventListener("input", () => input.value = (viewof N).valueAsNumber);
  return input;
}

```

…then sliding N doesn’t visually update M (although of course the value is indeed set, and Observable notices this).

---

<div class="post-metadata">

### Author: ![jashkenas](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/jashkenas/32/1778_2.png) [@jashkenas](https://talk.observablehq.com/u/jashkenas)
#### Post date: [July 11, 2018, 8:11pm UTC](https://talk.observablehq.com/t/linked-sliders-title-padding/973/2 "2018-07-11T20:11:19Z")

</div>

Hey Kelley,

Mike has a great tutorial on this topic:

> **[Synchronized Views](https://observablehq.com/@mbostock/synchronized-views)**
>
> An Observable notebook by Mike Bostock.

In short — to avoid the circularity, you use your own event listeners.

An alternative way to do it, that may or may not be cleaner for your use case, is to have both views mutate and observe an external `mutable` cell.

---

<div class="post-metadata">

### Author: ![jrus](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/jrus/32/586_2.png) [@jrus](https://talk.observablehq.com/u/jrus)
#### Post date: [July 12, 2018, 1:00am UTC](https://talk.observablehq.com/t/linked-sliders-title-padding/973/3 "2018-07-12T01:00:14Z")

</div>

It’s possible there is an easier way to do this. But anyway, my method using Mike’s `View` class is along the lines of …

> **[Linked sliders](https://observablehq.com/d/e4c5423cb52166fb)**
>
> An Observable notebook by Jacob Rus.

```
viewof slider_view = new View(127)

```

then

```
slider1 = {
  const slider = html`<input type=range name=r min=0 max=255 step=1>`;
  
  slider.oninput = () => viewof slider_value.value = slider.valueAsNumber;
  const update = () => slider.value = viewof slider_value.value;
  
  viewof slider_value.addEventListener("input", update);
  return Generators.disposable(slider, () => {
    viewof slider_value.removeEventListener("input", update);
  });
}
```

---

<div class="post-metadata">

### Author: ![kelleyvanevert](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/kelleyvanevert/32/169_2.png) [@kelleyvanevert](https://talk.observablehq.com/u/kelleyvanevert)
#### Post date: [July 12, 2018, 10:14am UTC](https://talk.observablehq.com/t/linked-sliders-title-padding/973/4 "2018-07-12T10:14:32Z")

</div>

Thanks 🙂

Yeah, somehow I thought it should have been / was easier; but thanks for building this solution for me, I really didn’t feel up to it.

(In action: [https://beta.observablehq.com/@kelleyvanevert/the-kolakoski-sequence](https://beta.observablehq.com/@kelleyvanevert/the-kolakoski-sequence) .)

---

<div class="post-metadata">

### Author: ![jrus](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/jrus/32/586_2.png) [@jrus](https://talk.observablehq.com/u/jrus)
#### Post date: [July 12, 2018, 4:12pm UTC](https://talk.observablehq.com/t/linked-sliders-title-padding/973/5 "2018-07-12T16:12:17Z")

</div>

I’ve been using this kind of thing in my project of the past few weeks,

> **[Apollo](https://observablehq.com/d/e639659056145e88)**
>
> An Observable notebook by Jacob Rus.

which still has a couple open research questions to solve and a good amount more explanation to write before it is fully baked (even if my work time wasn’t in units of ‘naptime’, we are traveling the next few weeks), so will probably not be published for another month or something.

---

<div class="post-metadata">

### Author: ![jashkenas](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/jashkenas/32/1778_2.png) [@jashkenas](https://talk.observablehq.com/u/jashkenas)
#### Post date: [July 12, 2018, 5:01pm UTC](https://talk.observablehq.com/t/linked-sliders-title-padding/973/6 "2018-07-12T17:01:27Z")

</div>

Just a side note, but @jrus — that draft is looking _extremely_ cool.

---

<div class="post-metadata">

### Author: ![kelleyvanevert](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/kelleyvanevert/32/169_2.png) [@kelleyvanevert](https://talk.observablehq.com/u/kelleyvanevert)
#### Post date: [July 12, 2018, 5:52pm UTC](https://talk.observablehq.com/t/linked-sliders-title-padding/973/7 "2018-07-12T17:52:08Z")

</div>

Yes, indeed 😃

(padding text)
