Help us understand the problem. What is going on with this article?

position:fixed;で固定したヘッダーを横方向だけスクロール可能にする奴(テスト)

More than 1 year has passed since last update.

最初に作ったやつ(firefox上のhtmlで)

window.addEventListener('scroll', function() {
  document.getElementById("header").style.marginLeft= "-"+ window.pageXOffset+ "px";
}, false);

googleで検索すると,jQuery使ったやつばっかりヒットするのでvanillaな奴をこさえてみました.
.style.marginLeftで指定する値が数値じゃ駄目なのには嵌った...
とりあえず動くので来たけど,ただ問題はaddEventListenerがhtaでは動かないことなんだよなあ.attachEventとかで動いてくれるとええんやけど(・ω・`)

htaで動いたやつ

window.attachEvent('scroll', function() {
    document.getElementById("header").style.Left= -document.documentElement.scrollLeft;
});

addEventListenerは動かないからattachEventに変えましたよ,
marginLeftは試してないけどLeftで大丈夫でしたよ,
pageXOffsetが全然駄目で,scrollLeftが使えましたよ,
documentじゃなくて,document.documentElementにしないと動きませんでしたよ,
StyleのLeftの値はhtaでは数値でも単位「px」追加した文字列でもどっちでも動作しましたよ.
とりあえずやりたい動作が叶ったので良かったです(´^ω^`)

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした